-2
oops :: Integer -> Integer -> Integer
oops a b
   | a == 0 = b
   | otherwise = oops (a - 1) (b + 1)

oopser :: Integer -> Integer -> Integer
oopser a b
   | a == b = b
   | otherwise = oopser (a + 1) (b - 1)

For which values a and b will the above two function terminate? If the function terminates, which value is returned with respect to those values for a and b? (answering the question for both functions separtely)...

In programming, how do we actually define the word 'Terminate'??

PeAcE
  • 89
  • 7
  • If we look at a calculation as a process, we can identify its start, and may identify its end. If the end is reached, we call it termination. If we look at a calculation as a partial function, termination is just definedness. – n. m. could be an AI Jun 10 '13 at 04:46

1 Answers1

2

Non-terminate means you call a function and that function never ever return back a value and you keep on waiting for it till eternity. Now you can decide what is eternity for you ;).

Now in your particular case, the 2 functions are recursive functions and to know whether a recursive function will terminate or not is to check if the "base condition" (i.e the condition in which the recursive function doesn't call itself) will ever be met or not.

In oops the base condition is a == 0 and in recursion a is decremented so if you pass a as -1 (or anything negative) to this function then it will never meet the base condition and hence never terminate. It will terminate for any a which is a positive number or zero.

Similarly in oopser if you pass any value of a greater then b it will never terminate. It will terminate when you pass a that is smaller than b or both are equal.

Ankur
  • 33,367
  • 2
  • 46
  • 72