Tutorial/Practical 30/10/91 Write the following functions in ml. (Note: life will be easier if you use the "world" source that I posted to you.) (1) val even = fn : int -> bool Check if an integer is even. (2) val odd = fn : int -> bool Check if an integer is odd. (3) val upto = fn : int -> int list Deliver a list of integers from 1 to n. (4) map odd/even over a list of integers. (5) val cp = fn : 'a list -> 'b list -> ('a * 'b) list Compute the "Cartesian Product" of two sets (example below) Formally we might say that "cp x y" is {(a,b)|a mo x; b mo y} - val x = upto 5; val x = [1,2,3,4,5] : int list - val y = upto 3; val y = [1,2,3] : int list - cp x y; val it = [(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3), (4,1),(4,2),(4,3),...] : (int * int) list - cp ["a","b","c","d"] ["red","white","blue"]; val it = [("a","red"),("a","white"),("a","blue"), ("b","red"),("b","white"),("b","blue"), ("c","red"),("c","white"),("c","blue"), ("d","red"),("d","white"),("d","blue"),...] : (string * string) list HINT: a number of implementations of cp are possible. One of these employs map, mapf, and collapse (see world source). (6) Compute the "Powerset" of S, namely P(S). The powerset P(S) is the set consisting of all subsets of S, including the empty set and S itself. It can be computed by removing some element x from S and recursively computing the powerset of S-{x}. Assume that |S|=n, then |P(S)| is 2 raised to the power n (ie. the nth element is either present or is absent). (7) Compute the permutations of a set S. For example "perm [1,2,3]" is [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]. Formally, "perm x" is {a::y|a mo x; y mo perms(x - {a})} Note: if |S| = n, then |perm S| = n!