40 likes | 46 Views
Explore constructing lambda expressions and examining the existence of normal forms in functional programming. Understand the step-by-step process with examples and verification techniques. Access the solutions to exercises in the provided link.
E N D
CS4026, first practical Answers to exercises
Answers to Items 1 and 3 can be found here: http://www.csd.abdn.ac.uk/~wvasconc/teaching/ CS4018/abdn.only/practical1_answ.pdf • Answers to Items 2 and 4 can be found on the next few pages
Item 2 (constructing a lamda expression for g) 1. You could write gx.2*((x*x)+3), but this has no separate function h. Since hx.(x*x)+3, g can be written as gx.(a.(a(x*x+3))(z.2*z)), or as gx.((z.2*z)(a.(a*a+3))(x)). To check your solution, apply your function to a number. For example: g(4) x.(a.(a(x*x+3))(z.2*z))(4) (a.(a(4*4)+3))(z.2*z) (z.2*z)((4*4)+3) 2*19 38
Item 2 (existence of normal forms) • (x.x)(x.x) Normal form (after 1 beta conversion step) is x.x • (x.xx)(x.x) Normal form (after two beta conversion steps) is x.x • (x.xx)(x.xx). No normal form. After beta conversion, you get (x.xx)(x.xx) once again, after which beta conversion applies again (etc.) • (x.xxx)(x.xxx). No normal form. After one beta conversion, you get (x.xxx)(x.xxx)(x.xxx). After two beta conversions you get (x.xxx)(x.xxx)(x.xxx)(x.xxx), and so on.