def mul(n,m): # compute n*m; n and m are nonnegative integers a = n b = m c = 0 # invariant ab+c = nm while a != 0: a = a - 1 c = c + b # (a-1)b + (c+b) = ab -b + c + b = ab+c = nm return c