{"id":1980,"date":"2016-01-14T06:00:02","date_gmt":"2016-01-14T04:00:02","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=1980"},"modified":"2016-01-21T09:06:09","modified_gmt":"2016-01-21T07:06:09","slug":"lista-tautologica-de-literales","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/lista-tautologica-de-literales\/","title":{"rendered":"Lista tautol\u00f3gica de literales"},"content":{"rendered":"<p>En l\u00f3gica matem\u00e1tica, un literal http:\/\/bit.ly\/1RQ5yJU es una f\u00f3rmula at\u00f3mica o su negaci\u00f3n. Se puede definir por el tipo de dato<\/p>\n<pre lang=\"text\"> \n   data Literal = Atom String\n                | Neg Literal\n                deriving (Eq, Show)\n<\/pre>\n<p>Por ejemplo, el literal los literales p y \u00acq se representan por las expresiones (Atom \u00abp\u00bb) y (Neg (Atom \u00abq\u00bb)), respectivamente.<\/p>\n<p>Una lista de literales (que se interpreta como su disyunci\u00f3n) es un tautolog\u00eda si contiene a una f\u00f3rmula at\u00f3mica y su negaci\u00f3n.<\/p>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\"> \n   tautologia :: [Literal] -> Bool\n<\/pre>\n<p>tal que (tautologia xs) se verifica si la lista de literales xs es una tautolog\u00eda. Por ejemplo,<\/p>\n<pre lang=\"text\"> \n   \u03bb> tautologia [Atom \"p\", Neg (Atom \"q\"), Neg (Atom \"p\")]\n   True\n   \u03bb> tautologia [Atom \"p\", Neg (Atom \"q\"), Neg (Atom \"r\")]\n   False\n   \u03bb> tautologia [Atom \"p\", Neg (Atom \"q\"), Neg (Atom \"q\")]\n   False\n<\/pre>\n<h4>Soluciones<\/h4>\n<p>[schedule expon=&#8217;2016-01-21&#8242; expat=\u00bb06:00&#8243;]<\/p>\n<ul>\n<li>Las soluciones se pueden escribir en los comentarios hasta el 21 de enero.\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;2016-01-21&#8242; at=\u00bb06:00&#8243;]<\/p>\n<pre lang=\"haskell\">\r\nimport Data.List (intersect)\r\n\r\ndata Literal = Atom String\r\n             | Neg Literal\r\n             deriving (Eq, Show)\r\n\r\n-- 1\u00aa soluci\u00f3n\r\n-- ===========\r\n\r\ntautologia1 :: [Literal] -> Bool\r\ntautologia1 xs = or [elem x xs && elem (Neg x) xs | x <- xs]\r\n\r\n-- 2\u00aa soluci\u00f3n\r\n-- ===========\r\n\r\ntautologia2 :: [Literal] -> Bool\r\ntautologia2 xs = \r\n    not (null (intersect ns (map neg ps)))\r\n    where (ps,ns) = span esPositivo xs\r\n          neg x   = Neg x\r\n\r\nesPositivo :: Literal -> Bool\r\nesPositivo (Atom _) = True\r\nesPositivo _        = False\r\n\r\n-- Comparaci\u00f3n de eficiencia\r\n-- =========================\r\n\r\n--    \u03bb> tautologia1 (replicate 4000 (Atom \"p\"))\r\n--    False\r\n--    (6.70 secs, 1031428 bytes)\r\n--    \u03bb> tautologia2 (replicate 4000 (Atom \"p\"))\r\n--    False\r\n--    (0.01 secs, 1061604 bytes)\r\n<\/pre>\n<p>[\/schedule]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>En l\u00f3gica matem\u00e1tica, un literal http:\/\/bit.ly\/1RQ5yJU es una f\u00f3rmula at\u00f3mica o su negaci\u00f3n. Se puede definir por el tipo de dato data Literal = Atom String | Neg Literal deriving (Eq, Show) Por ejemplo, el literal los literales p y \u00acq se representan por las expresiones (Atom \u00abp\u00bb) y (Neg (Atom \u00abq\u00bb)), respectivamente. Una lista&#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":[181,141,11,60,133],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1980"}],"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=1980"}],"version-history":[{"count":5,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1980\/revisions"}],"predecessor-version":[{"id":1990,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1980\/revisions\/1990"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=1980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=1980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=1980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}