Question

The following provides a pre and post condition for the gcd method.

pre: x > 0 & y > 0 
post: result > 0 &
      x mod result = 0 & y mod result = 0 &
      ∀t:Integer · t > 0 & x mod t = 0 & y mod t = 0 ⇒ result mod t = 0

However, I'm having trouble following the post condition... to me it basically says find any integer that is divisible by both. How does it get the maximum divisor, what are the conditions actually saying?

Was it helpful?

Solution

This one assures that result is the greatest of all common divisors.

∀t:Integer·t>0 & x mod t=0 & y mod t = 0 ⇒ result mod t = 0

It says that any t, which is a common divisor of x and y, is also a divisor of result

EDIT: you should read the above line like this:

∀t:Integer·((t>0 & x mod t=0 & y mod t = 0) ⇒ result mod t = 0)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top