{"id":4124,"date":"2018-05-31T06:00:06","date_gmt":"2018-05-31T04:00:06","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=4124"},"modified":"2021-04-25T16:04:14","modified_gmt":"2021-04-25T14:04:14","slug":"subexpresiones-aritmeticas-2018","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/subexpresiones-aritmeticas-2018\/","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<pre lang=\"haskell\">\nimport Data.Set\n\ndata Expr = N Int | S Expr Expr | P Expr Expr  \n  deriving (Eq, Ord, Show)\n\nsubexpresiones :: Expr -> Set Expr\nsubexpresiones (N x)   = singleton (N x)\nsubexpresiones (S i d) =\n  S i d `insert` (subexpresiones i `union` subexpresiones d)\nsubexpresiones (P i d) =\n  P i d `insert` (subexpresiones i `union` subexpresiones d)\n<\/pre>\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":[5],"tags":[331,459,6,133,242],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/4124"}],"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=4124"}],"version-history":[{"count":2,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/4124\/revisions"}],"predecessor-version":[{"id":4144,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/4124\/revisions\/4144"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=4124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=4124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=4124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}