7 views

Uploaded by tanmaya1991

ffgu

- Algebra 2 Final Exam Study Guide
- DESIGN OF SERVICE APPLICATION FOR AUTO DETAILING: A CASE STUDY OF JETWASH AUTO SPA TANGERANG
- Euthyphro’s Dilemma -- An attempt at formalized algebraic notation
- Yokogawa-controller-manual - Controlador Yokogawa UT 37 y Más.
- Introduction to Functions
- algebra i eoc released item
- Workshop Extra
- tManager Performance Considerations
- Oracle Apps flexfields Concepts
- November 6.docx
- hw - vertical transformations and function notation
- Java Homework
- Comrel 9.50 Demo - [Demo.bti]
- fall 2015 pipeline project
- fall 2015 pipeline project
- project
- Chapter 7 Graphs of Quadratics
- Gena Rise
- Final Exam Fall2013
- The Ring programming language version 1.5.2 book - Part 23 of 181

You are on page 1of 2

The solutions must be handed in directly before (very latest: at the beginning of ) the exercise course on Wednesday, 09.05.2012, 11:45, in lecture hall AH 2. Alternatively you can drop your solutions into a box which is located right next to Prof. Giesls oce (until the exercise course starts). Please write the names and immatriculation numbers of all (two) students on your solution. Also please staple the individual sheets!

(1 + 2 + 3 + 2 + 2 = 10 points)

In this exercise, we consider an alternative to the representation of polynomials presented on exercise sheet 2. Here, we use the following data type: data Expr = Operator ( Int -> Int -> Int ) Expr Expr | Variable String | Constant Int You can visualize a term of type Expr like t =Operator (*) (Operator (+) (Variable "x") (Constant 2)) (Constant 3) as a tree as follows: (*)

(+)

"x"

Here, each Operator node contains a function that describes how the values of its two children should be combined. a) To instantiate variables in a term of type Expr, we want to use substitutions as dened by type Substitution = String -> Int. Implement a function baseSubstitution :: Substitution such that every variable is mapped to 0. So for instance, baseSubstitution "x" returns 0. b) To build more complex substitutions, the function extendSubstitution :: Substitution -> String -> Int -> Substitution should be used. It takes an existing substition, a String s and an Int i, and returns a new substitution that maps s to i and otherwise behaves like the old substitution. For example, extendSubstitution baseSubstitution "x" 12 should return a substitution that maps "x" to 12 and every other String to 0. c) We now want to implement a fold function for Expr terms:

foldExpr :: ((Int -> Int -> Int) -> a -> a -> a) -> (String -> a) -> (Int -> a) -> Expr -> a

Analogously to other fold functions, foldExpr f g h e should yield a term in which every occurrence of Operator is replaced by f, every Variable by g, and every Constant by h. For example,

getVars = foldExpr (\_ l r -> l ++ r) (\s -> [s]) (\_ -> [])

should compute a list containing all variables of an Expr term, i.e., applied to t from above, it should yield ["x"].

Functional Programming SS12 Exercise Sheet 3 (due 09.05.2012) d) Implement a function countOperators :: Expr -> Int that counts how many Operator constructors occur in an Expr term. For example, for t from above, it should yield 2. Use foldExpr from part c). e) Finally, we want to evaluate terms of type Expr using a function evalExpr :: Substitution -> Expr -> Int. To evaluate evalExpr sub t, every variable in the term t should be instantiated as specied by sub. Then, all functions in Operator nodes should be applied to the (evaluated) subexpressions. For example, when evaluating the term t from above, with "x" instantiated by 12, the result should be 42. Use foldExpr from part c).

(1 + 1 + 2 + 2 + 2 + 2 = 10 points)

a) Implement a function conjunction :: [Bool] -> Bool. For an input list [b1 , b2 , . . . , bn ], conjunction returns True if all of the values [b1 , b2 , . . . , bn ] are True, i.e., if b1 b2 . . . bn is true. Do not use explicit recursion, but foldr. b) Implement a function universalQ :: (a -> Bool) -> [a] -> Bool that determines whether the property encoded by the rst argument holds for all elements of the list passed as second argument. For example, universalQ even list should yield True if all elements of list are even numbers. Do not use explicit recursion, but conjunction and map. c) Implement a function sortUsing :: (a -> a -> Bool) -> [a] -> [a] that sorts a list using a custom comparison function supplied by the user. If we have two elements x, y and the comparison function c returns True for c x y, then x should occur before y in the sorted list. For example, sortUsing (>) [1,2,3,4] should yield [4,3,2,1]. In this part of the exercise (and also in parts d)f )) you may use explicit recursion. d) Implement a function removeWhile :: (a -> Bool) -> [a] -> [a] that removes elements from the input list as long as the predicate given as rst argument is True for these elements. For example, removeWhile even [2,4,1,4] should yield [1,4]. e) Implement a function meld :: (a -> a -> b) -> [a] -> [b] that applies a function to every two consecutive elements in a list and returns a list containing the results. For example meld (+) [1, 2, 3, 4] = [3, 5, 7]. For lists xs with less than two elements, meld f xs returns []. f ) Implement a function partition :: (a -> Bool) -> [a] -> ([a], [a]) that gets a function f and a list l and splits the elements of l into two separate lists, such that the rst contains only the elements for which f returns True and the second contains only the elements for which f returns False. For example partition (\x -> x mod 2 == 0) [1,2,3,4,5] = ([2,4],[1,3,5]).

- Algebra 2 Final Exam Study GuideUploaded byMissPoulson
- DESIGN OF SERVICE APPLICATION FOR AUTO DETAILING: A CASE STUDY OF JETWASH AUTO SPA TANGERANGUploaded byIRJCS-INTERNATIONAL RESEARCH JOURNAL OF COMPUTER SCIENCE
- Euthyphro’s Dilemma -- An attempt at formalized algebraic notationUploaded byalgebraicphilosophy
- Yokogawa-controller-manual - Controlador Yokogawa UT 37 y Más.Uploaded byXavi X Qunqi
- Introduction to FunctionsUploaded bytree5215
- algebra i eoc released itemUploaded byapi-282887866
- Workshop ExtraUploaded byTooba Aamir
- tManager Performance ConsiderationsUploaded byJediael Junior
- Oracle Apps flexfields ConceptsUploaded byChary Madarapu
- November 6.docxUploaded byLovely Villas
- hw - vertical transformations and function notationUploaded byapi-368121935
- Java HomeworkUploaded bysyedasadali
- Comrel 9.50 Demo - [Demo.bti]Uploaded byGanesh Fakatkar
- fall 2015 pipeline projectUploaded byapi-296711038
- fall 2015 pipeline projectUploaded byapi-272471717
- projectUploaded byapi-324606765
- Chapter 7 Graphs of QuadraticsUploaded byXislea Novaes
- Gena RiseUploaded byAnonymous MqprQvjEK
- Final Exam Fall2013Uploaded byPatiram Yadav
- The Ring programming language version 1.5.2 book - Part 23 of 181Uploaded byMahmoud Samir Fayed
- The generalized Dice measures for multiple attribute decision making under simpliﬁed neutrosophic environmentsUploaded byMia Amalia
- 02 Core Java IntroTo LanguageUploaded bydukeyprince
- Bewässerungsanlage mit RohrverteilungUploaded byDixi Anonüm
- y7s16exUploaded byMohamed Fouad Korra
- Learning Pascal3Uploaded byaflayers
- 7_spatialanalysisUploaded byfaridagushybana
- calculus 1.docxUploaded byjennifer reyes
- es configure finalUploaded byapi-340769184
- Function (Mathematics) - WikipediaUploaded byroxalld
- dg10p1Uploaded byapi-3724082

- Solution2012-08-15-V3BUploaded bytanmaya1991
- Idea Presentation (Milestone 1) - TextUploaded bytanmaya1991
- Tarpana Sanskrit SsUploaded bytmn2011
- Career CounsellingUploaded bytanmaya1991
- A Formal Technique for Software Evolution Tanmaya Mahapatra 340959Uploaded bytanmaya1991
- ArticleUploaded bytanmaya1991
- Covering LetterUploaded bytanmaya1991
- Teaching SchemeUploaded bytanmaya1991
- SyllabusUploaded bytanmaya1991
- Module EnglishUploaded bytanmaya1991
- Guru Van i April 2005Uploaded bytanmaya1991
- Maa PitambaraUploaded byBharat Mishra
- Guru Wan i May June 2001Uploaded bytanmaya1991
- ishtadevata-2Uploaded bytanmaya1991
- Brief Guide Germany Aug2012Uploaded bytanmaya1991
- Aditya Hriday StotramUploaded byRitwik Yogi
- lordsivaUploaded by_moto_moto_
- e Intro TarpanamsUploaded byJagadiswari Rajamanikam
- batuka.psUploaded bytanmaya1991
- Exam2005 BlankUploaded bytanmaya1991
- V4-exam-20100319Uploaded bytanmaya1991
- Exercise 9Uploaded bytanmaya1991
- Exercise 7Uploaded bytanmaya1991
- Exercise 8Uploaded bytanmaya1991
- Exercise 6Uploaded bytanmaya1991
- Exercise 4Uploaded bytanmaya1991
- Exercise 2Uploaded bytanmaya1991
- Exercise 1Uploaded bytanmaya1991
- V3M-sol-20100224Uploaded bytanmaya1991

- Week 27 - Unit 13 - Good Deeds (R)Uploaded byFaizy Mudzakir
- Data Visualization Workshop ReportUploaded bymickamal
- Mapas da África 8000 ac 1500 dcUploaded byalzenbach
- EHT BendingToolsUploaded byAcaJoksimovic
- How to Use R Tutorials Connecting Fortran and RUploaded byisaias.prestes
- Exxon - OIMS_Framework_Brochure.pdfUploaded byeayujig
- Theoretical Approaches to the Study of Development2Uploaded byRenzelle Chiong
- 18964649 Study of Different Types of Pipe FittingsUploaded byOoi Thean Chun
- Sage x3 Legislation GuideUploaded byDanushka De Silva
- 1999 Issue 4 - Why I Want to Join the RPCUS - Counsel of ChalcedonUploaded byChalcedon Presbyterian Church
- Simaticpcs7 Stpcs7 Complete English 2012-06Uploaded bybajrica
- Curtin Scholarship FormUploaded byAshraf Noor
- 2572 001 EmerCall Master HandsetUploaded bylilama45-1
- Dedicated StorageUploaded byJunaidi Kun
- Sample ProblemsUploaded bydodoy kangkong
- CPU-finalUploaded bymkgchem
- Anchore Bolt FROM MEHEDIUploaded byhabibur Rahman Khan
- Ethics , Integrity & AptitudeUploaded byGourab Paul
- CNC Machine SafetyUploaded bykarthikkanda
- KALAUploaded byAcharla Narasimha Acharya
- ZnO Nano and Salinity and TemperatureUploaded byBrigita de Brillar
- flyer-hcna-cloud v1Uploaded byapi-309660805
- Sample of Lesson Plan CEFRUploaded byAmirAh KaMarudin
- Animal Farm ScriptUploaded byts pavan
- Incompressible flow-cambered airfoilUploaded byD.Viswanath
- EgyptUploaded byBradford Ohbliv
- Arctica Engine KavoUploaded byHsuan Chen
- Global Developmental Delay EvaluationUploaded byMuhammad Darussalam Darwis
- Training Loads DifferentlyUploaded byCésar Ayala Guzmán
- Internal Balistik PPT_uploadUploaded byazzzzz2076