On 30/10/2015, at 7:52 pm, Roelof Wobben <r.wobben@home.nl> wrote:
Let's say f is a recursive function which calculates the fac.
So f 0 = 0 f1 = 1 f2 = 2 f3 = 6
so im my oponion g1 = the answer of f1 which is also the max
True. But what if f is *NOT* the factorial? To quote your own original message, <quote> To test this function, add to your script a definition of some values of f thus: f 0 = 0 f 1 = 44 f 2 = 17 f _ = 0 and so on; then test your function at various values. </quote> This f is NOT the factorial function. For this f, we expect g n = if n == 0 then 0 else 44, so that (g n == f n) is false almost always. Let's consider the general pattern for a primitive recursive function on the natural numbers: g 0 otherArgs = b otherArgs g (n+1) otherArgs = c n (g n otherArgs) otherArgs where b(ase) and c(ombination) are primitive recursive. In this case, there are no otherArgs, so g 0 = <<some expression possibly involving f>> g n = <<some expression involving n, g (n-1), and f>> For exercise 4.22, you are given a hint that <<some expression involving n, g (n-1), and f>> will also involve a call to max. There's really not a lot of sensible ways you can put these together.