{"id":3855,"date":"2018-03-12T06:00:36","date_gmt":"2018-03-12T04:00:36","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=3855"},"modified":"2021-04-25T16:10:35","modified_gmt":"2021-04-25T14:10:35","slug":"la-conjetura-de-levy-2018","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/la-conjetura-de-levy-2018\/","title":{"rendered":"La conjetura de Levy"},"content":{"rendered":"<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Hyman_Levy\">Hyman Levy<\/a> observ\u00f3 que<\/p>\n<pre lang=\"text\">\n    7 = 3 + 2 x 2\n    9 = 3 + 2 x 3 =  5 + 2 x 2\n   11 = 5 + 2 x 3 =  7 + 2 x 2\n   13 = 3 + 2 x 5 =  7 + 2 x 3\n   15 = 3 + 2 x 5 = 11 + 2 x 2\n   17 = 3 + 2 x 7 =  7 + 2 x 5 = 11 + 2 x 3 = 13 + 2 x 2\n   19 = 5 + 2 x 7 = 13 + 2 x 3\n<\/pre>\n<p>y conjetur\u00f3 que todos los n\u00famero impares mayores o iguales que 7 se pueden escribir como la suma de un primo y el doble de un primo. El objetivo de los siguientes ejercicios es comprobar la <a href=\"http:\/\/mathworld.wolfram.com\/LevysConjecture.html\">conjetura de Levy<\/a>.<\/p>\n<p>Definir las siguientes funciones<\/p>\n<pre lang=\"text\">\n   descomposicionesLevy :: Integer -> [(Integer,Integer)]\n   graficaLevy          :: Integer -> IO ()\n<\/pre>\n<p>tales que<\/p>\n<ul>\n<li>(descomposicionesLevy x) es la lista de pares de primos (p,q) tales que x = p + 2q. Por ejemplo,<\/li>\n<\/ul>\n<pre lang=\"text\">\n     descomposicionesLevy  7  ==  [(3,2)]\n     descomposicionesLevy  9  ==  [(3,3),(5,2)]\n     descomposicionesLevy 17  ==  [(3,7),(7,5),(11,3),(13,2)]\n<\/pre>\n<ul>\n<li>(graficaLevy n) dibuja los puntos (x,y) tales que x pertenece a [7,9..7+2x(n-1)] e y es el n\u00famero de descomposiciones de Levy de x. Por ejemplo, (graficaLevy 200) dibuja<br \/>\n<a href=\"https:\/\/i0.wp.com\/www.glc.us.es\/~jalonso\/exercitium\/wp-content\/uploads\/2018\/03\/La_conjetura_de_Levy-200.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.glc.us.es\/~jalonso\/exercitium\/wp-content\/uploads\/2018\/03\/La_conjetura_de_Levy-200.png?resize=640%2C480\" alt=\"La_conjetura_de_Levy-200\" width=\"640\" height=\"480\" class=\"aligncenter size-full wp-image-3856\" srcset=\"https:\/\/i0.wp.com\/www.glc.us.es\/~jalonso\/exercitium\/wp-content\/uploads\/2018\/03\/La_conjetura_de_Levy-200.png?w=640&amp;ssl=1 640w, https:\/\/i0.wp.com\/www.glc.us.es\/~jalonso\/exercitium\/wp-content\/uploads\/2018\/03\/La_conjetura_de_Levy-200.png?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.glc.us.es\/~jalonso\/exercitium\/wp-content\/uploads\/2018\/03\/La_conjetura_de_Levy-200.png?resize=100%2C75&amp;ssl=1 100w, https:\/\/i0.wp.com\/www.glc.us.es\/~jalonso\/exercitium\/wp-content\/uploads\/2018\/03\/La_conjetura_de_Levy-200.png?resize=150%2C112&amp;ssl=1 150w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/a><\/li>\n<\/ul>\n<p>Comprobar con QuickCheck la conjetura de Levy.<\/p>\n<h4>Soluciones<\/h4>\n<p>[schedule on=&#8217;2018-03-19&#8242; at=\u00bb06:00&#8243;]<\/p>\n<pre lang=\"haskell\">\nimport Data.Numbers.Primes\nimport Test.QuickCheck\nimport Graphics.Gnuplot.Simple\n\ndescomposicionesLevy :: Integer -> [(Integer,Integer)]\ndescomposicionesLevy x =\n  [(p,q) | p <- takeWhile (< x) (tail primes)\n         , let q = (x - p) `div` 2\n         , isPrime q]\n\n-- graficaLevy 300\ngraficaLevy :: Integer -> IO ()\ngraficaLevy n =\n  plotList [ Key Nothing\n           , XRange (7,fromIntegral (7+2*(n-1)))\n           , PNG (\"La_conjetura_de_Levy-\" ++ show n ++ \".png\")\n           ]\n           [(x, length (descomposicionesLevy x)) | x <- [7,9..7+2*(n-1)]] \n\n-- La propiedad es\nprop_Levy :: Integer -> Bool\nprop_Levy x =\n  not (null (descomposicionesLevy (7 + 2 * abs x)))\n\n-- La comprobaci\u00f3n es\n--    \u03bb> quickCheck prop_Levy\n--    +++ OK, passed 100 tests.\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hyman Levy observ\u00f3 que 7 = 3 + 2 x 2 9 = 3 + 2 x 3 = 5 + 2 x 2 11 = 5 + 2 x 3 = 7 + 2 x 2 13 = 3 + 2 x 5 = 7 + 2 x 3 15 = 3 + 2&#8230;<\/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,"footnotes":"","_jetpack_memberships_contains_paid_content":false},"categories":[5],"tags":[130,8,30,376,174,28,181,141,11,309,173,45,34,146],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3855"}],"collection":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/comments?post=3855"}],"version-history":[{"count":2,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3855\/revisions"}],"predecessor-version":[{"id":3915,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3855\/revisions\/3915"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=3855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=3855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=3855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}