{"id":5793,"date":"2020-04-16T05:30:38","date_gmt":"2020-04-16T03:30:38","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=5793"},"modified":"2020-04-29T07:27:36","modified_gmt":"2020-04-29T05:27:36","slug":"matrices-de-hadamard","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/matrices-de-hadamard\/","title":{"rendered":"Matrices de Hadamard"},"content":{"rendered":"<p>Las <a href=\"http:\/\/bit.ly\/2vhsoGG\">matrices de Hadamard<\/a> se definen recursivamente como sigue<\/p>\n<pre lang=\"text\">\n   \u03bb> hadamard 0\n   ( 1 )\n   \n   \u03bb> hadamard 1\n   (  1  1 )\n   (  1 -1 )\n   \n   \u03bb> hadamard 2\n   (  1  1  1  1 )\n   (  1 -1  1 -1 )\n   (  1  1 -1 -1 )\n   (  1 -1 -1  1 )\n   \n   \u03bb> hadamard 3\n   (  1  1  1  1  1  1  1  1 )\n   (  1 -1  1 -1  1 -1  1 -1 )\n   (  1  1 -1 -1  1  1 -1 -1 )\n   (  1 -1 -1  1  1 -1 -1  1 )\n   (  1  1  1  1 -1 -1 -1 -1 )\n   (  1 -1  1 -1 -1  1 -1  1 )\n   (  1  1 -1 -1 -1 -1  1  1 )\n   (  1 -1 -1  1 -1  1  1 -1 )\n<\/pre>\n<p>En general, la n-\u00e9sima matriz de Hadamard, H(n), es<\/p>\n<pre lang=\"text\">\n   ( H(n-1)  H(n-1) )\n   ( H(n-1) -H(n-1) )\n<\/pre>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   hadamard :: Int -> Matrix Int\n<\/pre>\n<p>tal que (hadamard n) es la n-\u00e9sima matriz de Hadamard.<\/p>\n<p>Comprobar con QuickCheck que para todo n\u00famero natural n, el producto de la n-\u00e9sima matriz de Hadamard y su traspuesta es igual al producto de 2^n por la matriz identidad de orden 2^n.<\/p>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\nimport Data.Matrix (Matrix, identity, joinBlocks, scaleMatrix, transpose)\nimport Test.QuickCheck \n\nhadamard :: Int -> Matrix Int\nhadamard 0 = identity 1\nhadamard n = joinBlocks (a, a, a, b)\n  where a = hadamard (n-1)\n        b = scaleMatrix (-1) a\n\n-- La propiedad es\nprop_Hadamard :: (Positive Int) -> Bool\nprop_Hadamard (Positive n) =\n  h * transpose h == scaleMatrix (2^n) (identity (2^n))\n  where h = hadamard n\n\n-- La comprobaci\u00f3n es\n--    \u03bb> quickCheckWith (stdArgs {maxSize=7}) prop_Hadamard\n--    +++ OK, passed 100 tests.\n<\/pre>\n<h4>Otras soluciones<\/h4>\n<ul>\n<li>Se pueden escribir otras soluciones en los comentarios.\n<li>El c\u00f3digo se debe escribir entre una l\u00ednea con &#60;pre lang=&quot;haskell&quot;&#62; y otra con &#60;\/pre&#62;\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Las matrices de Hadamard se definen recursivamente como sigue \u03bb> hadamard 0 ( 1 ) \u03bb> hadamard 1 ( 1 1 ) ( 1 -1 ) \u03bb> hadamard 2 ( 1 1 1 1 ) ( 1 -1 1 -1 ) ( 1 1 -1 -1 ) ( 1 -1 -1 1 ) \u03bb> hadamard&#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":[446,447,42,448,68],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/5793"}],"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=5793"}],"version-history":[{"count":2,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/5793\/revisions"}],"predecessor-version":[{"id":5834,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/5793\/revisions\/5834"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=5793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=5793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=5793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}