{"id":8071,"date":"2024-01-20T10:13:04","date_gmt":"2024-01-20T09:13:04","guid":{"rendered":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/?p=8071"},"modified":"2024-01-27T10:16:40","modified_gmt":"2024-01-27T09:16:40","slug":"20-ene-24","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/20-ene-24\/","title":{"rendered":"La semana en Calculemus (20 de enero de 2024)"},"content":{"rendered":"\n<p>Esta semana he publicado en <a href=\"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/\">Calculemus<\/a> las demostraciones con Lean4 de las siguientes propiedades:<\/p>\n<ul>\n<li><a href=\"#ej1\">1. En \u211d, |x + y| \u2264 |x| + |y|<\/a><\/li>\n<li><a href=\"#ej2\">2. En \u211d, si x \u2260 0 entonces x &lt; 0 \u00f3 x > 0<\/a><\/li>\n<li><a href=\"#ej3\">3. Si m divide a n o a k, entonces m divide a nk<\/a><\/li>\n<li><a href=\"#ej4\">4. Si (\u2203 x, y \u2208 \u211d)(z = x\u00b2 + y\u00b2 \u2228 z = x\u00b2 + y\u00b2 + 1), entonces z \u2265 0<\/a><\/li>\n<li><a href=\"#ej5\">5. En \u211d, si x\u00b2 = 1 entonces x = 1 \u00f3 x = -1<\/a><\/li>\n<\/ul>\n<p>A continuaci\u00f3n se muestran las soluciones.<br \/>\n<!--more--><br \/>\n<a name=\"ej1\"><\/a><\/p>\n<h3>1. En \u211d, |x + y| \u2264 |x| + |y|<\/h3>\n<p>Demostrar con Lean4 que en &#92;(\u211d&#92;),<br \/>\n&#92;[ |x + y| \u2264 |x| + |y|&#92;]<\/p>\n<p>Para ello, completar la siguiente teor\u00eda de Lean4:<\/p>\n<pre lang=\"lean\">\nimport Mathlib.Data.Real.Basic\nvariable {x y : \u211d}\n\nexample : |x + y| \u2264 |x| + |y| :=\nby sorry\n<\/pre>\n<p><b>Demostraci\u00f3n en lenguaje natural<\/b><\/p>\n<p>Se usar\u00e1n los siguientes lemas<br \/>\n&#92;begin{align}<br \/>\n    &amp;(\u2200 x \u2208 \u211d)[0 \u2264 x \u2192 |x| = x)                         &#92;tag{L1} &#92;&#92;<br \/>\n    &amp;(\u2200 a, b, c, d \u2208 \u211d)[a \u2264 b \u2227 c \u2264 d \u2192 a + c \u2264 b + d]  &#92;tag{L2} &#92;&#92;<br \/>\n    &amp;(\u2200 x \u2208 \u211d)[x \u2264 |x|]                                 &#92;tag{L3} &#92;&#92;<br \/>\n    &amp;(\u2200 x \u2208 \u211d)[x &lt; 0 \u2192 |x| = -x]                        &#92;tag{L4} &#92;&#92;<br \/>\n    &amp;(\u2200 x, y \u2208 \u211d)[-(x + y) = -x + -y]                   &#92;tag{L5} &#92;&#92;<br \/>\n    &amp;(\u2200 x \u2208 \u211d)[-x \u2264 |x|]                                &#92;tag{L6}<br \/>\n&#92;end{align}<\/p>\n<p>Se demostrar\u00e1 por casos seg\u00fan &#92;(x + y \u2265 0&#92;):<\/p>\n<p>Primer caso: Supongamos que &#92;(x + y \u2265 0&#92;). Entonces,<br \/>\n&#92;begin{align}<br \/>\n   |x + y| &amp;= x + y        &amp;&amp;&#92;text{[por L1]} &#92;&#92;<br \/>\n           &amp;\u2264 |x| + |y|    &amp;&amp;&#92;text{[por L2 y L3]}<br \/>\n&#92;end{align}<\/p>\n<p>Segundo caso: Supongamos que &#92;(x + y &lt; 0&#92;). Entonces,<br \/>\n&#92;begin{align}<br \/>\n   |x + y| &amp;= -(x + y)     &amp;&amp;&#92;text{[por L4]} &#92;&#92;<br \/>\n           &amp;= -x + -y      &amp;&amp;&#92;text{[por L5]} &#92;&#92;<br \/>\n           &amp;\u2264 |x| + |y|    &amp;&amp;&#92;text{[por L2 y L6]}<br \/>\n&#92;end{align}<\/p>\n<p><b>Demostraciones con Lean4<\/b><\/p>\n<pre lang=\"lean\">\nimport Mathlib.Data.Real.Basic\nvariable {x y : \u211d}\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample : |x + y| \u2264 |x| + |y| :=\nby\n  rcases le_or_gt 0 (x + y) with h1 | h2\n  \u00b7 -- h1 : 0 \u2264 x + y\n    show |x + y| \u2264 |x| + |y|\n    calc |x + y| = x + y     := by exact abs_of_nonneg h1\n               _ \u2264 |x| + |y| := add_le_add (le_abs_self x) (le_abs_self y)\n  . -- h2 : 0 > x + y\n    show |x + y| \u2264 |x| + |y|\n    calc |x + y| = -(x + y)  := by exact abs_of_neg h2\n               _ = -x + -y   := by exact neg_add x y\n               _ \u2264 |x| + |y| := add_le_add (neg_le_abs_self x) (neg_le_abs_self y)\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : |x + y| \u2264 |x| + |y| := by\n  rcases le_or_gt 0 (x + y) with h1 | h2\n  \u00b7 -- h1 : 0 \u2264 x + y\n    rw [abs_of_nonneg h1]\n    -- \u22a2 x + y \u2264 |x| + |y|\n    exact add_le_add (le_abs_self x) (le_abs_self y)\n  . -- h2 : 0 > x + y\n    rw [abs_of_neg h2]\n    -- \u22a2 -(x + y) \u2264 |x| + |y|\n    calc -(x + y) = -x + -y    := by exact neg_add x y\n                _ \u2264 |x| + |y|  := add_le_add (neg_le_abs_self x) (neg_le_abs_self y)\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample : |x + y| \u2264 |x| + |y| := by\n  rcases le_or_gt 0 (x + y) with h1 | h2\n  \u00b7 -- h1 : 0 \u2264 x + y\n    rw [abs_of_nonneg h1]\n    -- \u22a2 x + y \u2264 |x| + |y|\n    linarith [le_abs_self x, le_abs_self y]\n  . -- h2 : 0 > x + y\n    rw [abs_of_neg h2]\n    -- \u22a2 -(x + y) \u2264 |x| + |y|\n    linarith [neg_le_abs_self x, neg_le_abs_self y]\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample : |x + y| \u2264 |x| + |y| :=\n  abs_add x y\n\n-- Lemas usados\n-- ============\n\n-- variable (a b c d : \u211d)\n-- #check (abs_add x y : |x + y| \u2264 |x| + |y|)\n-- #check (abs_of_neg : x < 0 \u2192 |x| = -x)\n-- #check (abs_of_nonneg : 0 \u2264 x \u2192 |x| = x)\n-- #check (add_le_add : a \u2264 b \u2192 c \u2264 d \u2192 a + c \u2264 b + d)\n-- #check (le_abs_self a : a \u2264 |a|)\n-- #check (le_or_gt x y : x \u2264 y \u2228 x > y)\n-- #check (neg_add x y : -(x + y) = -x + -y)\n-- #check (neg_le_abs_self x : -x \u2264 |x|)\n<\/pre>\n<p><b>Demostraciones interactivas<\/b><\/p>\n<p>Se puede interactuar con las demostraciones anteriores en <a href=\"https:\/\/live.lean-lang.org\/#url=https:\/\/raw.githubusercontent.com\/jaalonso\/Calculemus2\/main\/src\/Desigualdad_triangular_para_valor_absoluto.lean\" rel=\"noopener noreferrer\" target=\"_blank\">Lean 4 Web<\/a>.<\/p>\n<p><b>Referencias<\/b><\/p>\n<ul>\n<li> J. Avigad y P. Massot. <a href=\"https:\/\/bit.ly\/3U4UjBk\">Mathematics in Lean<\/a>, p. 38.<\/li>\n<\/ul>\n<p><a name=\"ej2\"><\/a><\/p>\n<h3>2. En \u211d, si x \u2260 0 entonces x &lt; 0 \u00f3 x > 0<\/h3>\n<p>Demostrar con Lean4 que en \u211d, si &#92;(x \u2260 0&#92;) entonces &#92;(x &lt; 0&#92;) \u00f3 &#92;(x > 0&#92;).<\/p>\n<p>Para ello, completar la siguiente teor\u00eda de Lean4:<\/p>\n<pre lang=\"lean\">\nimport Mathlib.Data.Real.Basic\nvariable {x : \u211d}\n\nexample\n  (h : x \u2260 0)\n  : x < 0 \u2228 x > 0 :=\nby sorry\n<\/pre>\n<p><b>Demostraci\u00f3n en lenguaje natural<\/b><\/p>\n<p>Usando el siguiente lema<br \/>\n&#92;[ (\u2200 x y \u2208 \u211d)[x &lt; y \u2228 x = y \u2228 y &lt; x] &#92;]<br \/>\nse demuestra distinguiendo tres casos.<\/p>\n<p>Caso 1: Supongamos que &#92;(x &lt; 0&#92;). Entonces, se verifica la disyunci\u00f3n ya<br \/>\nque se verifica su primera parte.<\/p>\n<p>Caso 2: Supongamos que &#92;(x = 0&#92;). Entonces, se tiene una contradicci\u00f3n<br \/>\ncon la hip\u00f3tesis.<\/p>\n<p>Caso 3: Supongamos que &#92;(x > 0&#92;). Entonces, se verifica la disyunci\u00f3n ya<br \/>\nque se verifica su segunda parte.<\/p>\n<p><b>Demostraciones con Lean4<\/b><\/p>\n<pre lang=\"lean\">\nimport Mathlib.Data.Real.Basic\nvariable {x : \u211d}\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : x \u2260 0)\n  : x < 0 \u2228 x > 0 :=\nby\n  rcases lt_trichotomy x 0 with hx1 | hx2 | hx3\n  . -- hx1 : x < 0\n    left\n    -- \u22a2 x < 0\n    exact hx1\n  . -- hx2 : x = 0\n    contradiction\n  . -- hx3 : 0 < x\n    right\n    -- \u22a2 x > 0\n    exact hx3\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : x \u2260 0)\n  : x < 0 \u2228 x > 0 :=\nNe.lt_or_lt h\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : x \u2260 0)\n  : x < 0 \u2228 x > 0 :=\nby aesop\n\n-- Lemas usados\n-- ============\n\n-- variable (y : \u211d)\n-- #check (lt_trichotomy x y : x < y \u2228 x = y \u2228 y < x)\n<\/pre>\n<p><b>Demostraciones interactivas<\/b><\/p>\n<p>Se puede interactuar con las demostraciones anteriores en <a href=\"https:\/\/live.lean-lang.org\/#url=https:\/\/raw.githubusercontent.com\/jaalonso\/Calculemus2\/main\/src\/Eliminacion_de_la_disyuncion_con_rcases.lean\" rel=\"noopener noreferrer\" target=\"_blank\">Lean 4 Web<\/a>.<\/p>\n<p><b>Referencias<\/b><\/p>\n<ul>\n<li> J. Avigad y P. Massot. <a href=\"https:\/\/bit.ly\/3U4UjBk\">Mathematics in Lean<\/a>, p. 39.<\/li>\n<\/ul>\n<p><a name=\"ej3\"><\/a><\/p>\n<h3>3. Si m divide a n o a k, entonces m divide a nk<\/h3>\n<p>Demostrar con Lean4 que si &#92;(m&#92;) divide a &#92;(n&#92;) o a &#92;(k&#92;), entonces &#92;(m&#92;) divide a &#92;(nk&#92;).<\/p>\n<p>Para ello, completar la siguiente teor\u00eda de Lean4:<\/p>\n<pre lang=\"lean\">\nimport Mathlib.Tactic\nvariable {m n k : \u2115}\n\nexample\n  (h : m \u2223 n \u2228 m \u2223 k)\n  : m \u2223 n * k :=\nby sorry\n<\/pre>\n<p><b>Demostraci\u00f3n en lenguaje natural<\/b><\/p>\n<p>Se demuestra por casos.<\/p>\n<p>Caso 1: Supongamos que &#92;(m \u2223 n&#92;). Entonces, existe un &#92;(a \u2208 \u2115&#92;) tal que<br \/>\n&#92;[ n = ma &#92;]<br \/>\nPor tanto,<br \/>\n&#92;begin{align}<br \/>\n   nk &amp;= (ma)k &#92;&#92;<br \/>\n      &amp;= m(ak)<br \/>\n&#92;end{align}<br \/>\nque es divisible por &#92;(m&#92;).<\/p>\n<p>Caso 2: Supongamos que &#92;(m \u2223 k). Entonces, existe un &#92;(b \u2208 \u2115&#92;) tal que<br \/>\n&#92;[ k = mb &#92;]<br \/>\nPor tanto,<br \/>\n&#92;begin{align}<br \/>\n   nk &amp;= n(mb) &#92;&#92;<br \/>\n      &amp;= m(nb)<br \/>\n&#92;end{align}<br \/>\nque es divisible por &#92;(m&#92;).<\/p>\n<p><b>Demostraciones con Lean4<\/b><\/p>\n<pre lang=\"lean\">\nimport Mathlib.Tactic\nvariable {m n k : \u2115}\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : m \u2223 n \u2228 m \u2223 k)\n  : m \u2223 n * k :=\nby\n  rcases h with h1 | h2\n  . -- h1 : m \u2223 n\n    rcases h1 with \u27e8a, ha\u27e9\n    -- a : \u2115\n    -- ha : n = m * a\n    rw [ha]\n    -- \u22a2 m \u2223 (m * a) * k\n    rw [mul_assoc]\n    -- \u22a2 m \u2223 m * (a * k)\n    exact dvd_mul_right m (a * k)\n  . -- h2 : m \u2223 k\n    rcases h2 with \u27e8b, hb\u27e9\n    -- b : \u2115\n    -- hb : k = m * b\n    rw [hb]\n    -- \u22a2 m \u2223 n * (m * b)\n    rw [mul_comm]\n    -- \u22a2 m \u2223 (m * b) * n\n    rw [mul_assoc]\n    -- \u22a2 m \u2223 m * (b * n)\n    exact dvd_mul_right m (b * n)\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : m \u2223 n \u2228 m \u2223 k)\n  : m \u2223 n * k :=\nby\n  rcases h with h1 | h2\n  . -- h1 : m \u2223 n\n    rcases h1 with \u27e8a, ha\u27e9\n    -- a : \u2115\n    -- ha : n = m * a\n    rw [ha, mul_assoc]\n    -- \u22a2 m \u2223 m * (a * k)\n    exact dvd_mul_right m (a * k)\n  . -- h2 : m \u2223 k\n    rcases h2 with \u27e8b, hb\u27e9\n    -- b : \u2115\n    -- hb : k = m * b\n    rw [hb, mul_comm, mul_assoc]\n    -- \u22a2 m \u2223 m * (b * n)\n    exact dvd_mul_right m (b * n)\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : m \u2223 n \u2228 m \u2223 k)\n  : m \u2223 n * k :=\nby\n  rcases h with \u27e8a, rfl\u27e9 | \u27e8b, rfl\u27e9\n  . -- a : \u2115\n    -- \u22a2 m \u2223 (m * a) * k\n    rw [mul_assoc]\n    -- \u22a2 m \u2223 m * (a * k)\n    exact dvd_mul_right m (a * k)\n  . -- \u22a2 m \u2223 n * (m * b)\n    rw [mul_comm, mul_assoc]\n    -- \u22a2 m \u2223 m * (b * n)\n    exact dvd_mul_right m (b * n)\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : m \u2223 n \u2228 m \u2223 k)\n  : m \u2223 n * k :=\nby\n  rcases h with h1 | h2\n  . -- h1 : m \u2223 n\n    exact dvd_mul_of_dvd_left h1 k\n  . -- h2 : m \u2223 k\n    exact dvd_mul_of_dvd_right h2 n\n\n-- Lemas usados\n-- ============\n\n-- #check (dvd_mul_of_dvd_left : m \u2223 n \u2192 \u2200 (c : \u2115), m \u2223 n * c)\n-- #check (dvd_mul_of_dvd_right : m \u2223 n \u2192 \u2200 (c : \u2115), m \u2223 c * n)\n-- #check (dvd_mul_right m n : m \u2223 m * n)\n-- #check (mul_assoc m n k : m * n * k = m * (n * k))\n-- #check (mul_comm m n : m * n = n * m)\n<\/pre>\n<p><b>Demostraciones interactivas<\/b><\/p>\n<p>Se puede interactuar con las demostraciones anteriores en <a href=\"https:\/\/live.lean-lang.org\/#url=https:\/\/raw.githubusercontent.com\/jaalonso\/Calculemus2\/main\/src\/CS_de_divisibilidad_del_producto.lean\" rel=\"noopener noreferrer\" target=\"_blank\">Lean 4 Web<\/a>.<\/p>\n<p><b>Referencias<\/b><\/p>\n<ul>\n<li> J. Avigad y P. Massot. <a href=\"https:\/\/bit.ly\/3U4UjBk\">Mathematics in Lean<\/a>, p. 39.<\/li>\n<\/ul>\n<p><b>Demostraciones con Isabelle\/HOL<\/b><\/p>\n<pre lang=\"isar\">\ntheory CS_de_divisibilidad_del_producto\n  imports Main\nbegin\n\n(* 1\u00aa demostraci\u00f3n *)\nlemma\n  fixes n m k :: nat\n  assumes \"m dvd n \u2228 m dvd k\"\n  shows \"m dvd (n * k)\"\nusing assms\nproof\n    assume \"m dvd n\"\n    then obtain a where \"n = m * a\" by auto\n    then have \"n * k = m * (a * k)\" by simp\n    then show ?thesis by auto\n  next\n    assume \"m dvd k\"\n    then obtain b where \"k = m * b\" by auto\n    then have \"n * k = m * (n * b)\" by simp\n    then show ?thesis by auto\nqed\n\n(* 2\u00aa demostraci\u00f3n *)\nlemma\n  fixes n m k :: nat\n  assumes \"m dvd n \u2228 m dvd k\"\n  shows \"m dvd (n * k)\"\n  using assms by auto\n\nend\n<\/pre>\n<p><a name=\"ej4\"><\/a><\/p>\n<h3>4. Si (\u2203 x, y \u2208 \u211d)[z = x\u00b2 + y\u00b2 \u2228 z = x\u00b2 + y\u00b2 + 1], entonces z \u2265 0<\/h3>\n<p>Demostrar con Lean4 que si &#92;((\u2203 x, y \u2208 \u211d)[z = x\u00b2 + y\u00b2 \u2228 z = x\u00b2 + y\u00b2 + 1]&#92;), entonces &#92;(z \u2265 0&#92;).<\/p>\n<p>Para ello, completar la siguiente teor\u00eda de Lean4:<\/p>\n<pre lang=\"lean\">\nimport Mathlib.Data.Real.Basic\nimport Mathlib.Tactic\nvariable {z : \u211d}\n\nexample\n  (h : \u2203 x y, z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1)\n  : z \u2265 0 :=\nby sorry\n<\/pre>\n<h2>Demostraci\u00f3n en lenguaje natural<\/h2>\n<p>Usaremos los siguientes lemas<br \/>\n&#92;begin{align}<br \/>\n   &amp;(\u2200 x \u2208 \u211d)[x\u00b2 \u2265 0]                                              &#92;tag{L1} &#92;&#92;<br \/>\n   &amp;(\u2200 x, y \u2208 \u211d)[x \u2265 0 \u2192 y \u2265 0 \u2192 x + y \u2265 0]                        &#92;tag{L2} &#92;&#92;<br \/>\n   &amp;1 \u2265 0                                                          &#92;tag{L3}<br \/>\n&#92;end{align}<\/p>\n<p>Sean &#92;(a&#92;) y &#92;(b&#92;) tales que<br \/>\n&#92;[ z = a\u00b2 + b\u00b2 \u2228 z = a\u00b2 + b\u00b2 + 1 &#92;]<br \/>\nEntonces, por L1, se tiene que<br \/>\n&#92;begin{align}<br \/>\n   &amp;a\u00b2 \u2265 0                                                         &#92;tag{1} &#92;&#92;<br \/>\n   &amp;b\u00b2 \u2265 0                                                         &#92;tag{2}<br \/>\n&#92;end{align}<\/p>\n<p>En el primer caso, &#92;(z = a\u00b2 + b\u00b2&#92;) y se tiene que &#92;(z \u2265 0&#92;) por el lema L2 aplicado a (1) y (2).<\/p>\n<p>En el segundo caso, &#92;(z = a\u00b2 + b\u00b2 + 1&#92;) y se tiene que &#92;(z \u2265 0&#92;) por el lema L2 aplicado a (1), (2) y L3.<\/p>\n<h2>Demostraciones con Lean4<\/h2>\n<pre lang=\"lean\">\nimport Mathlib.Data.Real.Basic\nimport Mathlib.Tactic\nvariable {z : \u211d}\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : \u2203 x y, z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1)\n  : z \u2265 0 :=\nby\n  rcases h with \u27e8a, b, h1\u27e9\n  -- a b : \u211d\n  -- h1 : z = a ^ 2 + b ^ 2 \u2228 z = a ^ 2 + b ^ 2 + 1\n  have h2 : a ^ 2 \u2265 0 := pow_two_nonneg a\n  have h3 : b ^ 2 \u2265 0 := pow_two_nonneg b\n  have h4 : a ^ 2 + b ^ 2 \u2265 0 := add_nonneg h2 h3\n  rcases h1 with h5 | h6\n  . -- h5 : z = a ^ 2 + b ^ 2\n    show z \u2265 0\n    calc z = a ^ 2 + b ^ 2 := h5\n         _ \u2265 0             := add_nonneg h2 h3\n  . -- h6 : z = a ^ 2 + b ^ 2 + 1\n    show z \u2265 0\n    calc z = (a ^ 2 + b ^ 2) + 1 := h6\n         _ \u2265 0                   := add_nonneg h4 zero_le_one\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : \u2203 x y, z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1)\n  : z \u2265 0 :=\nby\n  rcases h with \u27e8a, b, h1 | h2\u27e9\n  . -- h1 : z = a ^ 2 + b ^ 2\n    have h1a : a ^ 2 \u2265 0 := pow_two_nonneg a\n    have h1b : b ^ 2 \u2265 0 := pow_two_nonneg b\n    show z \u2265 0\n    calc z = a ^ 2 + b ^ 2 := h1\n         _ \u2265 0             := add_nonneg h1a h1b\n  . -- h2 : z = a ^ 2 + b ^ 2 + 1\n    have h2a : a ^ 2 \u2265 0         := pow_two_nonneg a\n    have h2b : b ^ 2 \u2265 0         := pow_two_nonneg b\n    have h2c : a ^ 2 + b ^ 2 \u2265 0 := add_nonneg h2a h2b\n    show z \u2265 0\n    calc z = (a ^ 2 + b ^ 2) + 1 := h2\n         _ \u2265 0                   := add_nonneg h2c zero_le_one\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : \u2203 x y, z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1)\n  : z \u2265 0 :=\nby\n  rcases h with \u27e8a, b, h1 | h2\u27e9\n  . -- h1 : z = a ^ 2 + b ^ 2\n    rw [h1]\n    -- \u22a2 a ^ 2 + b ^ 2 \u2265 0\n    apply add_nonneg\n    . -- \u22a2 0 \u2264 a ^ 2\n      apply pow_two_nonneg\n    . -- \u22a2 0 \u2264 b ^ 2\n      apply pow_two_nonneg\n  . -- h2 : z = a ^ 2 + b ^ 2 + 1\n    rw [h2]\n    -- \u22a2 a ^ 2 + b ^ 2 + 1 \u2265 0\n    apply add_nonneg\n    . -- \u22a2 0 \u2264 a ^ 2 + b ^ 2\n      apply add_nonneg\n      . -- \u22a2 0 \u2264 a ^ 2\n        apply pow_two_nonneg\n      . -- \u22a2 0 \u2264 b ^ 2\n        apply pow_two_nonneg\n    . -- \u22a2 0 \u2264 1\n      exact zero_le_one\n\n-- 4\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : \u2203 x y, z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1)\n  : z \u2265 0 :=\nby\n  rcases h with \u27e8a, b, rfl | rfl\u27e9\n  . -- \u22a2 a ^ 2 + b ^ 2 \u2265 0\n    apply add_nonneg\n    . -- \u22a2 0 \u2264 a ^ 2\n      apply pow_two_nonneg\n    . -- \u22a2 0 \u2264 b ^ 2\n      apply pow_two_nonneg\n  . -- \u22a2 a ^ 2 + b ^ 2 + 1 \u2265 0\n    apply add_nonneg\n    . -- \u22a2 0 \u2264 a ^ 2 + b ^ 2\n      apply add_nonneg\n      . -- \u22a2 0 \u2264 a ^ 2\n        apply pow_two_nonneg\n      . -- \u22a2 0 \u2264 b ^ 2\n        apply pow_two_nonneg\n    . -- \u22a2 0 \u2264 1\n      exact zero_le_one\n\n-- 5\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : \u2203 x y, z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1)\n  : z \u2265 0 :=\nby\n  rcases h with \u27e8a, b, rfl | rfl\u27e9\n  . -- \u22a2 a ^ 2 + b ^ 2 \u2265 0\n    nlinarith\n  . -- \u22a2 a ^ 2 + b ^ 2 + 1 \u2265 0\n    nlinarith\n\n-- 6\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : \u2203 x y, z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1)\n  : z \u2265 0 :=\nby rcases h with \u27e8a, b, rfl | rfl\u27e9 <;> nlinarith\n\n-- Lemas usados\n-- ============\n\n-- variable (x y : \u211d)\n-- #check (add_nonneg : 0 \u2264 x \u2192 0 \u2264 y \u2192 0 \u2264 x + y)\n-- #check (pow_two_nonneg x : 0 \u2264 x ^ 2)\n-- #check (zero_le_one : 0 \u2264 1)\n<\/pre>\n<h2>Demostraciones interactivas<\/h2>\n<p>Se puede interactuar con las demostraciones anteriores en <a href=\"https:\/\/live.lean-lang.org\/#url=https:\/\/raw.githubusercontent.com\/jaalonso\/Calculemus2\/main\/src\/Desigualdad_con_rcases.lean\" rel=\"noopener noreferrer\" target=\"_blank\">Lean 4 Web<\/a>.<\/p>\n<h2>Referencias<\/h2>\n<ul>\n<li> J. Avigad y P. Massot. <a href=\"https:\/\/bit.ly\/3U4UjBk\">Mathematics in Lean<\/a>, p. 39.<\/li>\n<\/ul>\n<h2>Demostraciones con Isabelle\/HOL<\/h2>\n<pre lang=\"isar\">\ntheory Desigualdad_con_rcases\n  imports Main \"HOL.Real\"\nbegin\n\n(* 1\u00aa demostraci\u00f3n *)\nlemma\n  assumes \"\u2203x y :: real. (z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1)\"\n  shows \"z \u2265 0\"\nproof -\n  obtain x y where hxy: \"z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1\"\n    using assms by auto\n  { assume \"z = x^2 + y^2\"\n    have \"x^2 + y^2 \u2265 0\" by simp\n    then have \"z \u2265 0\" using `z = x^2 + y^2` by simp }\n  { assume \"z = x^2 + y^2 + 1\"\n    have \"x^2 + y^2 \u2265 0\" by simp\n    then have \"z \u2265 1\" using `z = x^2 + y^2 + 1` by simp }\n  with hxy show \"z \u2265 0\" by auto\nqed\n\n(* 2\u00aa demostraci\u00f3n *)\nlemma\n  assumes \"\u2203x y :: real. (z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1)\"\n  shows \"z \u2265 0\"\nproof -\n  obtain x y where hxy: \"z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1\"\n    using assms by auto\n  with hxy show \"z \u2265 0\" by auto\nqed\n\n(* 3\u00aa demostraci\u00f3n *)\nlemma\n  assumes \"\u2203x y :: real. (z = x^2 + y^2 \u2228 z = x^2 + y^2 + 1)\"\n  shows \"z \u2265 0\"\n  using assms by fastforce\n\nend\n<\/pre>\n<p><a name=\"ej5\"><\/a><\/p>\n<h3>5. En \u211d, si x\u00b2 = 1 entonces x = 1 \u00f3 x = -1<\/h3>\n<p>Demostrar con Lean4 que en &#92;(\u211d&#92;), si &#92;(x\u00b2 = 1&#92;) entonces &#92;(x = 1&#92;) \u00f3 &#92;(x = -1&#92;).<\/p>\n<p>Para ello, completar la siguiente teor\u00eda de Lean4:<\/p>\n<pre lang=\"lean\">\nimport Mathlib.Data.Real.Basic\nvariable (x y : \u211d)\n\nexample\n  (h : x^2 = 1)\n  : x = 1 \u2228 x = -1 :=\nby sorry\n<\/pre>\n<h2>Demostraci\u00f3n en lenguaje natural<\/h2>\n<p>Usaremos los siguientes lemas<br \/>\n&#92;begin{align}<br \/>\n   &amp;(\u2200 x \u2208 \u211d)[x - x = 0]                                           &#92;tag{L1} &#92;&#92;<br \/>\n   &amp;(\u2200 x, y \u2208 \u211d)[xy = 0 \u2192 x = 0 \u2228 y = 0]                           &#92;tag{L2} &#92;&#92;<br \/>\n   &amp;(\u2200 x, y \u2208 \u211d)[x - y = 0 \u2194 x = y]                                &#92;tag{L3} &#92;&#92;<br \/>\n   &amp;(\u2200 x, y \u2208 \u211d)[x + y = 0 \u2192 x = -y]                               &#92;tag{L4}<br \/>\n&#92;end{align}<\/p>\n<p>Se tiene que<br \/>\n&#92;begin{align}<br \/>\n   (x - 1)(x + 1) &amp;= x\u00b2 - 1     &#92;&#92;<br \/>\n                  &amp;= 1 - 1      &amp;&amp;&#92;text{[por la hip\u00f3tesis]} &#92;&#92;<br \/>\n                  &amp;= 0          &amp;&amp;&#92;text{[por L1]}<br \/>\n&#92;end{align}<br \/>\ny, por el lema L2, se tiene que<br \/>\n&#92;[ x - 1 = 0 \u2228 x + 1 = 0 &#92;]<br \/>\nAcabaremos la demostraci\u00f3n por casos.<\/p>\n<p>Primer caso:<br \/>\n&#92;begin{align}<br \/>\n  x - 1 = 0 &amp;\u27f9 x = 1             &amp;&amp;&#92;text{[por L3]} &#92;&#92;<br \/>\n            &amp;\u27f9 x = 1 \u2228 x = -1<br \/>\n&#92;end{align}<\/p>\n<p>Segundo caso:<br \/>\n&#92;begin{align}<br \/>\n  x + 1 = 0 &amp;\u27f9 x = -1            &amp;&amp;&#92;text{[por L4]} &#92;&#92;<br \/>\n            &amp;\u27f9 x = 1 \u2228 x = -1<br \/>\n&#92;end{align}<\/p>\n<h2>Demostraciones con Lean4<\/h2>\n<pre lang=\"lean\">\nimport Mathlib.Data.Real.Basic\nvariable (x y : \u211d)\n\n-- 1\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : x^2 = 1)\n  : x = 1 \u2228 x = -1 :=\nby\n  have h1 : (x - 1) * (x + 1) = 0 := by\n    calc (x - 1) * (x + 1) = x^2 - 1 := by ring\n                         _ = 1 - 1   := by rw [h]\n                         _ = 0       := sub_self 1\n  have h2 : x - 1 = 0 \u2228 x + 1 = 0 := by\n    apply eq_zero_or_eq_zero_of_mul_eq_zero h1\n  rcases h2 with h3 | h4\n  . -- h3 : x - 1 = 0\n    left\n    -- \u22a2 x = 1\n    exact sub_eq_zero.mp h3\n  . -- h4 : x + 1 = 0\n    right\n    -- \u22a2 x = -1\n    exact eq_neg_of_add_eq_zero_left h4\n\n-- 2\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : x^2 = 1)\n  : x = 1 \u2228 x = -1 :=\nby\n  have h1 : (x - 1) * (x + 1) = 0 := by nlinarith\n  have h2 : x - 1 = 0 \u2228 x + 1 = 0 := by aesop\n  rcases h2 with h3 | h4\n  . -- h3 : x - 1 = 0\n    left\n    -- \u22a2 x = 1\n    linarith\n  . -- h4 : x + 1 = 0\n    right\n    -- \u22a2 x = -1\n    linarith\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : x^2 = 1)\n  : x = 1 \u2228 x = -1 :=\nsq_eq_one_iff.mp h\n\n-- 3\u00aa demostraci\u00f3n\n-- ===============\n\nexample\n  (h : x^2 = 1)\n  : x = 1 \u2228 x = -1 :=\nby aesop\n\n-- Lemas usados\n-- ============\n\n-- #check (eq_neg_of_add_eq_zero_left : x + y = 0 \u2192 x = -y)\n-- #check (eq_zero_or_eq_zero_of_mul_eq_zero : x * y = 0 \u2192 x = 0 \u2228 y = 0)\n-- #check (sq_eq_one_iff : x ^ 2 = 1 \u2194 x = 1 \u2228 x = -1)\n-- #check (sub_eq_zero : x - y = 0 \u2194 x = y)\n-- #check (sub_self x : x - x = 0)\n<\/pre>\n<h2>Demostraciones interactivas<\/h2>\n<p>Se puede interactuar con las demostraciones anteriores en <a href=\"https:\/\/live.lean-lang.org\/#url=https:\/\/raw.githubusercontent.com\/jaalonso\/Calculemus2\/main\/src\/Cuadrado_igual_a_uno.lean\" rel=\"noopener noreferrer\" target=\"_blank\">Lean 4 Web<\/a>.<\/p>\n<h2>Referencias<\/h2>\n<ul>\n<li> J. Avigad y P. Massot. <a href=\"https:\/\/bit.ly\/3U4UjBk\">Mathematics in Lean<\/a>, p. 39.<\/li>\n<\/ul>\n<h2>Demostraciones con Isabelle\/HOL<\/h2>\n<pre lang=\"isar\">\ntheory Cuadrado_igual_a_uno\n  imports Main HOL.Real\nbegin\n\n(* 1\u00aa demostraci\u00f3n *)\nlemma\n  fixes x :: real\n  assumes \"x^2 = 1\"\n  shows \"x = 1 \u2228 x = -1\"\nproof -\n  have \"(x - 1) * (x + 1) = x^2 - 1\"\n    by algebra\n  also have \"... = 0\"\n    using assms by simp\n  finally have \"(x - 1) * (x + 1) = 0\" .\n  moreover\n  { assume \"(x - 1) = 0\"\n    then have \"x = 1\"\n      by simp }\n  moreover\n  { assume \"(x + 1) = 0\"\n    then have \"x = -1\"\n      by simp }\n  ultimately show \"x = 1 \u2228 x = -1\"\n    by auto\nqed\n\n(* 2\u00aa demostraci\u00f3n *)\nlemma\n  fixes x :: real\n  assumes \"x^2 = 1\"\n  shows \"x = 1 \u2228 x = -1\"\nproof -\n  have \"(x - 1) * (x + 1) = x^2 - 1\"\n    by algebra\n  also have \"... = 0\"\n    using assms by simp\n  finally have \"(x - 1) * (x + 1) = 0\" .\n  then show \"x = 1 \u2228 x = -1\"\n    by auto\nqed\n\n(* 3\u00aa demostraci\u00f3n *)\nlemma\n  fixes x :: real\n  assumes \"x^2 = 1\"\n  shows \"x = 1 \u2228 x = -1\"\nproof -\n  have \"(x - 1) * (x + 1) = 0\"\n  proof -\n    have \"(x - 1) * (x + 1) = x^2 - 1\" by algebra\n    also have \"\u2026 = 0\" by (simp add: assms)\n    finally show ?thesis .\n  qed\n  then show \"x = 1 \u2228 x = -1\"\n    by auto\nqed\n\n(* 4\u00aa demostraci\u00f3n *)\nlemma\n  fixes x :: real\n  assumes \"x^2 = 1\"\n  shows \"x = 1 \u2228 x = -1\"\nusing assms power2_eq_1_iff by blast\n\nend\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Esta semana he publicado en Calculemus las demostraciones con Lean4 de las siguientes propiedades: 1. En \u211d, |x + y| \u2264 |x| + |y| 2. En \u211d, si x \u2260 0 entonces x &lt; 0 \u00f3 x > 0 3. Si m divide a n o a k, entonces m divide a nk 4. Si&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"footnotes":"","_jetpack_memberships_contains_paid_content":false},"categories":[1],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/wp-json\/wp\/v2\/posts\/8071"}],"collection":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/wp-json\/wp\/v2\/comments?post=8071"}],"version-history":[{"count":3,"href":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/wp-json\/wp\/v2\/posts\/8071\/revisions"}],"predecessor-version":[{"id":8074,"href":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/wp-json\/wp\/v2\/posts\/8071\/revisions\/8074"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/wp-json\/wp\/v2\/media?parent=8071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/wp-json\/wp\/v2\/categories?post=8071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/vestigium\/wp-json\/wp\/v2\/tags?post=8071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}