I have a function computes n^(2n) and I need to prove by it by induction. Here it is in python:
def n_to_2n(n):
product = 1
counter = n
while counter > 0:
product = product * n * n
counter -= 1
return product
I believe I've found a useful loop invariant: product = n^(2*(n - counter)). For initialization and termination, this LI is trivial to prove, but I'm having difficulty proving the maintenance stage by induction. There's two variables, so which one do I perform induction on? I tried on n but didn't get anywhere really.
Assume LI(n) holds, prove LI(n + 1): ???
whileloop,counteris $n - i$ andproductis $n^{2i}$. – Mark Saving Sep 20 '21 at 15:56