1

A question about the definition of termination functions.

We have a relatively simple function for calculating ⌊log₂ n⌋ of an input.

LOG2
Configuration: {[r, n] | Integers r ≥ 0 and n ≥ 1}
[r, n] -> [r + 1, n/2] if n > 1 ∧ n even
[r, n] -> [r, n − 1] if n > 1 ∧ n odd

And we are asked whether some termination functions μ(r,n) are correct.

  • μ(r,n)= n is correct: the function's end condition is when n = 1, as at that point r = ⌊log₂ n₀⌋.

  • However, μ(r,n)=2n+r is apparently also correct.

  • Furthermore, μ(r,n) = n + r is incorrect

It was my understanding that the termination function μ(r,n) was simply the variable that the functions termination was dependent upon, (In this case n reaching 1,) so why is 2n+r a termination function?

What is the exact definition of termination function μ(r,n) in this context?

Cactus
  • 27,075
  • 9
  • 69
  • 149
Thomas B
  • 61
  • 3

1 Answers1

1

The termination function μ must be positive for states where the loop is entered, and strictly decreasing by every iteration. That, plus the well-orderedness of natural numbers ensures that your loop will always terminate. (Note that there is no requirement that μ(s) = 1 for s that exits the loop, just that it always decreases per iteration.)

The problem with choosing μ(r,n) = n + r is that for n = 2, we have

  • n even
  • n > 1

and so the transition [r, n] -> [r + 1, n / 2] is valid. However, in this case, we'd have

μ(r',n') =         Definition of r' and n'
μ(r+1,n/2) =       Definition of μ
r + 1 + n/2 =      Rearrange via n = 2
r + 2 = 
r + n =            Definition of μ
μ(r, n)

so μ doesn't strictly decrease.

Cactus
  • 27,075
  • 9
  • 69
  • 149