Proof Annotations For Arithmetic

On ProofAnnotationsForBubbleSort there was a point about value ranges on parameters (array-length in particular). I will try to elaborate on this one here by using a simple example with arithmetic.

  int mac(int a, int b, int c)
  {
    // variant a) [int.min <= a*b+c <= int.max]
    // variant b) [abs(a) < short.max && abs(b) < short.max-1 && abs(c) < int.max/2]

int r = a*b+c;

// [r == (num)a * (num)b + (num)c] return r; }

The usual problem with arithmetic on real hardware is overflow. At least it is, if proofs are considered. Here we have a simple MultiplyAccumulate with limited machine types ("int"), that can overflow (say, because we want the code to be correct, but fast). It may overflow the "int" range (say 32 bit) due to both multiplication or addition. But we want the result to be correct, i.e. equal to the 'same' calculation on true integer types ("num", see proof annotation before the return).

How do we ensure this? For some values we definitly will have overflow.

See ProofsCanBeSimple, AutomatedTheoremProving, ProofOfCorrectness


EditText of this page (last edited July 20, 2005) or FindPage with title or text search