I have the following function:
int mult(int y, int z)
{
if (z == 0)
return 0;
else if (z % 2 == 1)
return mult(2 * y, z / 2) + y;
else
return mult(2 * y, z / 2);
}
What I need to do is prove its correctness by induction. Now the trouble I'm having is that even though I know it works since I ran it I can't follow each individual step.
What is confusing me is that y
only shows up as an argument and in no place does it show up in a return except in the recursive part, and yet the function actually returns y
as the answer.
How does this happen? I need to be able to follow everything that happens so that I can do the iterations of it for the proof.