{"id":1999,"date":"2016-01-20T06:00:15","date_gmt":"2016-01-20T04:00:15","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=1999"},"modified":"2022-03-26T12:12:46","modified_gmt":"2022-03-26T10:12:46","slug":"antiimagenes-en-una-funcion-creciente","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/antiimagenes-en-una-funcion-creciente\/","title":{"rendered":"Antiim\u00e1genes en una funci\u00f3n creciente"},"content":{"rendered":"<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   antiimagen :: (Int -> Int) -> Int -> Maybe Int\n<\/pre>\n<p>tal que (antiimagen f y) es justo el x tal que f(x) = y, si y pertenece a la imagen de la funci\u00f3n creciente f, o nada, en caso contrario. Por ejemplo,<\/p>\n<pre lang=\"text\">\n   antiimagen (^2) 25  ==  Just 5\n   antiimagen (^3) 25  ==  Nothing\n<\/pre>\n<p><strong>Nota<\/strong>. Se supone que f est\u00e1 definida sobre los n\u00fameros naturales.<\/p>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\n-- 1\u00aa definici\u00f3n\n-- =============\n\nantiimagen1 :: (Int -> Int) -> Int -> Maybe Int\nantiimagen1 f y \n    | estaEnImagen f y = Just x\n    | otherwise        = Nothing\n    where x = head [x | x <- [0..], f x == y]\n\n-- (estaEnImagen f y) se verifica si pertenece a la imagen de f. Por\n-- ejemplo, \n--    estaEnImagen (^2) 25 == True\n--    estaEnImagen (^2) 30 == False\nestaEnImagen :: (Int -> Int) -> Int -> Bool\nestaEnImagen f y = elem y (takeWhile (<=y) (imagen f)) \n\n-- (imagen f) es la imagen de f. Por ejemplo,\n--    take 10 (imagen (^2))  ==  [0,1,4,9,16,25,36,49,64,81]\n--    take 10 (imagen (*3))  ==  [0,3,6,9,12,15,18,21,24,27]\nimagen :: (Int -> Int) -> [Int]\nimagen f = map f [0..]\n\n-- 2\u00aa definici\u00f3n (con lookup y maxBound)\n-- =====================================\n\nantiimagen2 :: (Int -> Int) -> Int -> Maybe Int\nantiimagen2 f y =\n    lookup y (takeWhile (<= (y,maxBound)) [(f x, x) | x <- [0..]])\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Definir la funci\u00f3n antiimagen :: (Int -> Int) -> Int -> Maybe Int tal que (antiimagen f y) es justo el x tal que f(x) = y, si y pertenece a la imagen de la funci\u00f3n creciente f, o nada, en caso contrario. Por ejemplo, antiimagen (^2) 25 == Just 5 antiimagen (^3) 25 ==&#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":[4],"tags":[500,26,415,10,11,34],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1999"}],"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=1999"}],"version-history":[{"count":4,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1999\/revisions"}],"predecessor-version":[{"id":2048,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1999\/revisions\/2048"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=1999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=1999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=1999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}