I am currently revising for my maths exam in school and there is a section on recursion. The question is explained as follows: $$f(m, n) =\begin{cases} n + 1 &\text{if } m = 0\\ f(m − 1, 1) &\text{if } m > 0 \text{ and } n = 0\\ f(m − 1, f(m, n − 1)) &\text{if } m > 0 \text{ and } n > 0\\ \end{cases}$$
calculate:
1) $f(1,1)$
2) $f(1,2)$
My current problem is i don't understand how my teacher arrives at this answer:
$$f(1, 1) = f(0, f(1, 0)) = f(1, 0) + 1 = f(0, 1) + 1 = 1 + 1 + 1 = 3$$
and:
$$f(1, 2) = f(0, f(1, 1)) = f(1, 1) + 1 = 3 + 1 = 4$$
I understand the principle of recursion but I am struggling to execute the above, could somebody work through the example $f(1,1)$ so I can how how it is done?
These are the steps for 1): \begin{align} f(1, 1) &= f(0, f(1, 0)) &\text{by rule 3}\\\\ &= f(0, f(0, 1)) & \text{by rule 2}\\\\ &= f(0, 2) & \text{by rule 1}\\\\ &= 3 & \text{by rule 1} \end{align}
The steps for 2), knowing the value of $f(1, 1)$ are \begin{align} f(1, 2) &= f(0, f(1, 1)) & \text{by rule 3}\\\\ &= f(0, 3) & \text{by the above}\\\\ &= 4 &\text{by rule 1} \end{align}