{"id":3333,"date":"2017-05-26T11:10:51","date_gmt":"2017-05-26T09:10:51","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=3333"},"modified":"2021-04-25T17:03:43","modified_gmt":"2021-04-25T15:03:43","slug":"subexpresiones-aritmeticas-17","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/subexpresiones-aritmeticas-17\/","title":{"rendered":"Subexpresiones aritm\u00e9ticas"},"content":{"rendered":"<p>Las expresiones aritm\u00e9ticas pueden representarse usando el siguiente tipo de datos<\/p>\n<pre lang=\"text\">\n   data Expr = N Int | S Expr Expr | P Expr Expr  \n     deriving (Eq, Ord, Show)\n<\/pre>\n<p>Por ejemplo, la expresi\u00f3n <code>2*(3+7)<\/code> se representa por<\/p>\n<pre lang=\"text\">\n   P (N 2) (S (N 3) (N 7))\n<\/pre>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   subexpresiones :: Expr -> Set Expr\n<\/pre>\n<p>tal que (subexpresiones e) es el conjunto de las subexpresiones de e. Por ejemplo,<\/p>\n<pre lang=\"text\">\n   \u03bb> subexpresiones (S (N 2) (N 3))\n   fromList [N 2,N 3,S (N 2) (N 3)]\n   \u03bb> subexpresiones (P (S (N 2) (N 2)) (N 7))\n   fromList [N 2,N 7,S (N 2) (N 2),P (S (N 2) (N 2)) (N 7)]\n<\/pre>\n<h4>Soluciones<\/h4>\n<p>[schedule expon=&#8217;2017-06-02&#8242; expat=\u00bb06:00&#8243;]<\/p>\n<ul>\n<li>Las soluciones se pueden escribir en los comentarios hasta el 02 de junio.\n<li>El c\u00f3digo se debe escribir entre una l\u00ednea con &#60;pre lang=\u00bbhaskell\u00bb&#62; y otra con &#60;\/pre&#62;\n<\/ul>\n<p>[\/schedule]<\/p>\n<p>[schedule on=&#8217;2017-06-02&#8242; at=\u00bb06:00&#8243;]<\/p>\n<pre lang=\"haskell\">\r\nimport Data.Set\r\n\r\ndata Expr = N Int | S Expr Expr | P Expr Expr  \r\n  deriving (Eq, Ord, Show)\r\n\r\nsubexpresiones :: Expr -> Set Expr\r\nsubexpresiones (N x)   = singleton (N x)\r\nsubexpresiones (S i d) =\r\n  S i d `insert` (subexpresiones i `union` subexpresiones d)\r\nsubexpresiones (P i d) =\r\n  P i d `insert` (subexpresiones i `union` subexpresiones d)\r\n<\/pre>\n<p>[\/schedule]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Las expresiones aritm\u00e9ticas pueden representarse usando el siguiente tipo de datos data Expr = N Int | S Expr Expr | P Expr Expr deriving (Eq, Ord, Show) Por ejemplo, la expresi\u00f3n 2*(3+7) se representa por P (N 2) (S (N 3) (N 7)) Definir la funci\u00f3n subexpresiones :: Expr -> Set Expr tal que&#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":[2],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3333"}],"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=3333"}],"version-history":[{"count":2,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3333\/revisions"}],"predecessor-version":[{"id":3335,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3333\/revisions\/3335"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=3333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=3333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=3333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}