        {"id":580,"date":"2021-07-18T08:05:32","date_gmt":"2021-07-18T06:05:32","guid":{"rendered":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/?p=580"},"modified":"2021-07-18T11:15:17","modified_gmt":"2021-07-18T09:15:17","slug":"teorema-del-emparedado","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/teorema-del-emparedado\/","title":{"rendered":"Teorema del emparedado"},"content":{"rendered":"<p>En Lean, una sucesi\u00f3n u\u2080, u\u2081, u\u2082, &#8230; se puede representar mediante una funci\u00f3n (u : \u2115 \u2192 \u211d) de forma que u(n) es u\u2099.<\/p>\n<p>Se define que a es el l\u00edmite de la sucesi\u00f3n u, por<\/p>\n<pre lang=\"text\">\n   def limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop :=\n   \u03bb u a, \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - a| < \u03b5\n<\/pre>\n<p>donde se usa la notaci\u00f3n |x| para el valor absoluto de x<\/p>\n<pre lang=\"text\">\n   notation `|`x`|` := abs x\n<\/pre>\n<p>Demostrar el <a href=\"https:\/\/bit.ly\/3eqlZ0b\">teorema del emparedado<\/a>; es decir, que si para todo n, u(n) \u2264 v(n) \u2264 w(n) y u(n) tiene el mismo l\u00edmite que w(n), entonces v(n) tambi\u00e9n tiene dicho l\u00edmite.<\/p>\n<p>Para ello, completar la siguiente teor\u00eda de Lean:<\/p>\n<pre lang=\"lean\">\nimport data.real.basic\n\nvariables (u v w : \u2115 \u2192 \u211d)\nvariable  (a : \u211d)\n\nnotation `|`x`|` := abs x\n\ndef limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop :=\n\u03bb u c, \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - c| \u2264 \u03b5\n\nexample\n  (hu : limite u a)\n  (hw : limite w a)\n  (h : \u2200 n, u n \u2264 v n)\n  (h' : \u2200 n, v n \u2264 w n) :\n  limite v a :=\nsorry\n<\/pre>\n<p>[expand title=\"Soluciones con Lean\"]<\/p>\n<pre lang=\"lean\">\r\nimport data.real.basic\r\n\r\nvariables (u v w : \u2115 \u2192 \u211d)\r\nvariable  (a : \u211d)\r\n\r\nnotation `|`x`|` := abs x\r\n\r\ndef limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop :=\r\n\u03bb u c, \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n - c| \u2264 \u03b5\r\n\r\n-- Nota. En la demostraci\u00f3n se usar\u00e1 el siguiente lema:\r\nlemma max_ge_iff\r\n  {p q r : \u2115}\r\n  : r \u2265 max p q \u2194 r \u2265 p \u2227 r \u2265 q :=\r\nmax_le_iff\r\n\r\n-- 1\u00aa demostraci\u00f3n\r\n-- ===============\r\n\r\nexample\r\n  (hu : limite u a)\r\n  (hw : limite w a)\r\n  (h : \u2200 n, u n \u2264 v n)\r\n  (h' : \u2200 n, v n \u2264 w n) :\r\n  limite v a :=\r\nbegin\r\n  intros \u03b5 h\u03b5,\r\n  cases hu \u03b5 h\u03b5 with N hN, clear hu,\r\n  cases hw \u03b5 h\u03b5 with N' hN', clear hw h\u03b5,\r\n  use max N N',\r\n  intros n hn,\r\n  rw max_ge_iff at hn,\r\n  specialize hN n hn.1,\r\n  specialize hN' n hn.2,\r\n  specialize h n,\r\n  specialize h' n,\r\n  clear hn,\r\n  rw abs_le at *,\r\n  split,\r\n  { calc -\u03b5\r\n         \u2264 u n - a : hN.1\r\n     ... \u2264 v n - a : by linarith, },\r\n  { calc v n - a\r\n         \u2264 w n - a : by linarith\r\n     ... \u2264 \u03b5       : hN'.2, },\r\nend\r\n\r\n-- 2\u00aa demostraci\u00f3n\r\nexample\r\n  (hu : limite u a)\r\n  (hw : limite w a)\r\n  (h : \u2200 n, u n \u2264 v n)\r\n  (h' : \u2200 n, v n \u2264 w n) :\r\n  limite v a :=\r\nbegin\r\n  intros \u03b5 h\u03b5,\r\n  cases hu \u03b5 h\u03b5 with N hN, clear hu,\r\n  cases hw \u03b5 h\u03b5 with N' hN', clear hw h\u03b5,\r\n  use max N N',\r\n  intros n hn,\r\n  rw max_ge_iff at hn,\r\n  specialize hN n (by linarith),\r\n  specialize hN' n (by linarith),\r\n  specialize h n,\r\n  specialize h' n,\r\n  rw abs_le at *,\r\n  split,\r\n  { linarith, },\r\n  { linarith, },\r\nend\r\n\r\n-- 3\u00aa demostraci\u00f3n\r\nexample\r\n  (hu : limite u a)\r\n  (hw : limite w a)\r\n  (h : \u2200 n, u n \u2264 v n)\r\n  (h' : \u2200 n, v n \u2264 w n) :\r\n  limite v a :=\r\nbegin\r\n  intros \u03b5 h\u03b5,\r\n  cases hu \u03b5 h\u03b5 with N hN, clear hu,\r\n  cases hw \u03b5 h\u03b5 with N' hN', clear hw h\u03b5,\r\n  use max N N',\r\n  intros n hn,\r\n  rw max_ge_iff at hn,\r\n  specialize hN n (by linarith),\r\n  specialize hN' n (by linarith),\r\n  specialize h n,\r\n  specialize h' n,\r\n  rw abs_le at *,\r\n  split ; linarith,\r\nend\r\n\r\n-- 4\u00aa demostraci\u00f3n\r\nexample\r\n  (hu : limite u a)\r\n  (hw : limite w a)\r\n  (h : \u2200 n, u n \u2264 v n)\r\n  (h' : \u2200 n, v n \u2264 w n) :\r\n  limite v a :=\r\nassume \u03b5,\r\nassume h\u03b5 : \u03b5 > 0,\r\nexists.elim (hu \u03b5 h\u03b5)\r\n  ( assume N,\r\n    assume hN : \u2200 (n : \u2115), n \u2265 N \u2192 |u n - a| \u2264 \u03b5,\r\n    exists.elim (hw \u03b5 h\u03b5)\r\n      ( assume N',\r\n        assume hN' : \u2200 (n : \u2115), n \u2265 N' \u2192 |w n - a| \u2264 \u03b5,\r\n        show \u2203 N, \u2200 n, n \u2265 N \u2192 |v n - a| \u2264 \u03b5, from\r\n          exists.intro (max N N')\r\n            ( assume n,\r\n              assume hn : n \u2265 max N N',\r\n              have h1 : n \u2265 N \u2227 n \u2265 N',\r\n                from max_ge_iff.mp hn,\r\n              have h2 : -\u03b5 \u2264 v n - a,\r\n                { have h2a : |u n - a| \u2264 \u03b5,\r\n                    from hN n h1.1,\r\n                  calc -\u03b5\r\n                       \u2264 u n - a : and.left (abs_le.mp h2a)\r\n                   ... \u2264 v n - a : by linarith [h n], },\r\n              have h3 : v n - a \u2264 \u03b5,\r\n                { have h3a : |w n - a| \u2264 \u03b5,\r\n                    from hN' n h1.2,\r\n                  calc v n - a\r\n                       \u2264 w n - a : by linarith [h' n]\r\n                   ... \u2264 \u03b5       : and.right (abs_le.mp h3a), },\r\n              show |v n - a| \u2264 \u03b5,\r\n                from abs_le.mpr (and.intro h2 h3))))\r\n<\/pre>\n<p>Se puede interactuar con la prueba anterior en <a href=\"https:\/\/leanprover-community.github.io\/lean-web-editor\/#url=https:\/\/raw.githubusercontent.com\/jaalonso\/Calculemus\/main\/src\/Teorema_del_emparedado.lean\" rel=\"noopener noreferrer\" target=\"_blank\">esta sesi\u00f3n con Lean<\/a>.<\/p>\n<p>En los comentarios se pueden escribir otras soluciones, escribiendo el c\u00f3digo entre una l\u00ednea con &#60;pre lang=&quot;lean&quot;&#62; y otra con &#60;\/pre&#62;<br \/>\n[\/expand]<\/p>\n<p>[expand title=\"Soluciones con Isabelle\/HOL\"]<\/p>\n<pre lang=\"isar\">\r\ntheory Teorema_del_emparedado\r\nimports Main HOL.Real\r\nbegin\r\n\r\ndefinition limite :: \"(nat \u21d2 real) \u21d2 real \u21d2 bool\"\r\n  where \"limite u c \u27f7 (\u2200\u03b5>0. \u2203k::nat. \u2200n\u2265k. \u00a6u n - c\u00a6 < \u03b5)\"\r\n\r\nlemma\r\n  assumes \"limite u a\"\r\n          \"limite w a\"\r\n          \"\u2200n. u n \u2264 v n\"\r\n          \"\u2200n. v n \u2264 w n\"\r\n  shows   \"limite v a\"\r\nproof (unfold limite_def; intro allI impI)\r\n  fix \u03b5 :: real\r\n  assume h\u03b5 : \"0 < \u03b5\"\r\n  obtain N where hN : \"\u2200n\u2265N. \u00a6u n - a\u00a6 < \u03b5\"\r\n    using assms(1) h\u03b5 limite_def\r\n    by auto\r\n  obtain N' where hN' : \"\u2200n\u2265N'. \u00a6w n - a\u00a6 < \u03b5\"\r\n    using assms(2) h\u03b5 limite_def\r\n    by auto\r\n  have \"\u2200n\u2265max N N'. \u00a6v n - a\u00a6 < \u03b5\"\r\n  proof (intro allI impI)\r\n    fix n\r\n    assume hn : \"n\u2265max N N'\"\r\n    have \"v n - a < \u03b5\"\r\n    proof -\r\n      have \"v n - a \u2264 w n - a\"\r\n        using assms(4) by simp\r\n      also have \"\u2026 \u2264 \u00a6w n - a\u00a6\"\r\n        by simp\r\n      also have \"\u2026 < \u03b5\"\r\n        using hN' hn by auto\r\n      finally show \"v n - a < \u03b5\" .\r\n    qed\r\n    moreover\r\n    have \"-(v n - a) < \u03b5\"\r\n    proof -\r\n      have \"-(v n - a) \u2264 -(u n - a)\"\r\n        using assms(3) by auto\r\n      also have \"\u2026 \u2264 \u00a6u n - a\u00a6\"\r\n        by simp\r\n      also have \"\u2026 < \u03b5\"\r\n        using hN hn by auto\r\n      finally show \"-(v n - a) < \u03b5\" .\r\n    qed\r\n    ultimately show \"\u00a6v n - a\u00a6 < \u03b5\"\r\n      by (simp only: abs_less_iff)\r\n  qed\r\n  then show \"\u2203k. \u2200n\u2265k. \u00a6v n - a\u00a6 < \u03b5\"\r\n    by (rule exI)\r\nqed\r\n\r\nend\r\n<\/pre>\n<p>En los comentarios se pueden escribir otras soluciones, escribiendo el c\u00f3digo entre una l\u00ednea con &#60;pre lang=&quot;isar&quot;&#62; y otra con &#60;\/pre&#62;<br \/>\n[\/expand]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>En Lean, una sucesi\u00f3n u\u2080, u\u2081, u\u2082, &#8230; se puede representar mediante una funci\u00f3n (u : \u2115 \u2192 \u211d) de forma que u(n) es u\u2099. Se define que a es el l\u00edmite de la sucesi\u00f3n u, por def limite : (\u2115 \u2192 \u211d) \u2192 \u211d \u2192 Prop := \u03bb u a, \u2200 \u03b5 > 0, \u2203 N, \u2200 n \u2265 N, |u n &#8211; a| < \u03b5 donde se usa la notaci\u00f3n |x| para el valor absoluto de x notation `|`x`|` := abs x Demostrar el teorema del emparedado; es decir, que si para todo n, u(n) \u2264 v(n) \u2264 w(n) y u(n) tiene el mismo l\u00edmite que w(n), entonces v(n) tambi\u00e9n tiene dicho l\u00edmite. Para ello, completar la siguiente teor\u00eda de Lean: import data.real.basic...\n<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","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,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[14],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/wp-json\/wp\/v2\/posts\/580"}],"collection":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/wp-json\/wp\/v2\/comments?post=580"}],"version-history":[{"count":2,"href":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/wp-json\/wp\/v2\/posts\/580\/revisions"}],"predecessor-version":[{"id":582,"href":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/wp-json\/wp\/v2\/posts\/580\/revisions\/582"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/wp-json\/wp\/v2\/media?parent=580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/wp-json\/wp\/v2\/categories?post=580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/calculemus\/wp-json\/wp\/v2\/tags?post=580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}