Proving Algorithms by Tail Functions