Beispiel #1
0
 public InvariantStatus check_modified(long value, int count) {
   if (modulus == 1) {
     // We shouldn't ever get to this case; the invariant should have been
     // destroyed instead.
     throw new Error("Modulus = 1");
   } else if (no_samples_seen) {
     return InvariantStatus.NO_CHANGE;
   } else if (value == value1) {
     // no new information, so nothing to do
     return InvariantStatus.NO_CHANGE;
   } else if (modulus == 0) {
     // only one value seen so far
     // REACHABLE?
     if (modulus == 1) {
       return InvariantStatus.FALSIFIED;
     }
   } else {
     long new_modulus_long = Math.abs(MathMDE.gcd(modulus, value1 - value));
     int new_modulus;
     if (new_modulus_long > Integer.MAX_VALUE || (new_modulus_long < Integer.MIN_VALUE)) {
       new_modulus = 1;
     } else {
       new_modulus = (int) new_modulus_long;
       assert new_modulus > 0;
     }
     if (new_modulus != modulus) {
       if (new_modulus == 1) {
         return InvariantStatus.FALSIFIED;
       }
     }
   }
   assert modulus != 1;
   return InvariantStatus.NO_CHANGE;
 }
Beispiel #2
0
  public InvariantStatus add_modified(long value, int count) {
    if (modulus == 1) {
      // We shouldn't ever get to this case; the invariant should have been
      // destroyed instead.
      throw new Error("Modulus = 1");
      // assert falsified;
      // // We already know this confidence fails
      // return;
    } else if (no_samples_seen) {
      value1 = value;
      no_samples_seen = false;
      return InvariantStatus.NO_CHANGE;
    } else if (value == value1) {
      // no new information, so nothing to do
      return InvariantStatus.NO_CHANGE;
    } else if (modulus == 0) {
      // only one value seen so far
      long new_modulus = Math.abs(value1 - value);

      if (new_modulus == 1) {
        return InvariantStatus.FALSIFIED;
      }
      modulus = new_modulus;
      remainder = MathMDE.mod_positive(value, modulus);
    } else {
      long new_modulus_long = Math.abs(MathMDE.gcd(modulus, value1 - value));
      int new_modulus;
      if (new_modulus_long > Integer.MAX_VALUE || (new_modulus_long < Integer.MIN_VALUE)) {
        new_modulus = 1;
      } else {
        new_modulus = (int) new_modulus_long;
        assert new_modulus > 0;
      }
      if (new_modulus != modulus) {
        if (new_modulus == 1) {
          return InvariantStatus.FALSIFIED;
        } else {
          remainder = remainder % new_modulus;
          modulus = new_modulus;
        }
      }
    }
    assert modulus != 1;
    return InvariantStatus.NO_CHANGE;
  }