DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Package Verada.Lemmas.Arithmetic

Verada.Lemmas.Arithmetic: facts of integer arithmetic, the nonlinear ones above all, that solvers do not find by themselves inside a larger proof: order under multiplication and division, signs, squares, quotients and remainders. Each is a ghost procedure whose postcondition is proved (by Verada's release gate, like the rest of the library); call one where a proof needs its fact as a step. Products and quotients are stated in Long_Long_Long_Integer (128 bits), so that no lemma has an overflow to rule out first.

Big

subtype Big is Long_Long_Long_Integer;

Lemma_Mult_Is_Monotonic

procedure Lemma_Mult_Is_Monotonic (Val1, Val2, Val3 : Integer)
  with Ghost, Global => null,
       Pre => Val1 <= Val2 and Val3 >= 0,
       Post => Big (Val1) * Big (Val3) <= Big (Val2) * Big (Val3);

multiplication by a value of known sign keeps or reverses order

Lemma_Mult_Is_Strictly_Monotonic

procedure Lemma_Mult_Is_Strictly_Monotonic (Val1, Val2, Val3 : Integer)
  with Ghost, Global => null,
       Pre => Val1 < Val2 and Val3 > 0,
       Post => Big (Val1) * Big (Val3) < Big (Val2) * Big (Val3);

Lemma_Mult_Is_Antimonotonic

procedure Lemma_Mult_Is_Antimonotonic (Val1, Val2, Val3 : Integer)
  with Ghost, Global => null,
       Pre => Val1 <= Val2 and Val3 <= 0,
       Post => Big (Val1) * Big (Val3) >= Big (Val2) * Big (Val3);

Lemma_Mult_Non_Negative

procedure Lemma_Mult_Non_Negative (Val1, Val2 : Integer)
  with Ghost, Global => null,
       Pre => (Val1 >= 0 and Val2 >= 0) or (Val1 <= 0 and Val2 <= 0),
       Post => Big (Val1) * Big (Val2) >= 0;

a product's sign

Lemma_Mult_Non_Positive

procedure Lemma_Mult_Non_Positive (Val1, Val2 : Integer)
  with Ghost, Global => null,
       Pre => (Val1 >= 0 and Val2 <= 0) or (Val1 <= 0 and Val2 >= 0),
       Post => Big (Val1) * Big (Val2) <= 0;

Lemma_Mult_Abs

procedure Lemma_Mult_Abs (Val1, Val2 : Integer)
  with Ghost, Global => null,
       Pre => Val1 > Integer'First and Val2 > Integer'First,
       Post => abs (Big (Val1) * Big (Val2)) = Big (abs Val1) * Big (abs Val2);

a product's size

Lemma_Mult_Bounded

procedure Lemma_Mult_Bounded (Val1, Val2, Bound1, Bound2 : Integer)
  with Ghost, Global => null,
       Pre => Val1 in 0 .. Bound1 and Val2 in 0 .. Bound2,
       Post => Big (Val1) * Big (Val2) <= Big (Bound1) * Big (Bound2);

Lemma_Square_Is_Monotonic

procedure Lemma_Square_Is_Monotonic (Val1, Val2 : Integer)
  with Ghost, Global => null,
       Pre => 0 <= Val1 and Val1 <= Val2,
       Post => Big (Val1) * Big (Val1) <= Big (Val2) * Big (Val2);

squares

Lemma_Square_Non_Negative

procedure Lemma_Square_Non_Negative (Val : Integer)
  with Ghost, Global => null,
       Post => Big (Val) * Big (Val) >= 0;

Lemma_Div_Is_Monotonic

procedure Lemma_Div_Is_Monotonic (Val1, Val2, Val3 : Integer)
  with Ghost, Global => null,
       Pre => Val1 <= Val2 and Val3 > 0,
       Post => Val1 / Val3 <= Val2 / Val3;

division by a positive value keeps order; a larger divisor gives less

Lemma_Div_Is_Antimonotonic

procedure Lemma_Div_Is_Antimonotonic (Val1, Val2, Val3 : Integer)
  with Ghost, Global => null,
       Pre => Val1 >= 0 and 0 < Val2 and Val2 <= Val3,
       Post => Val1 / Val3 <= Val1 / Val2;

Lemma_Div_Then_Mult_Bounds

procedure Lemma_Div_Then_Mult_Bounds (Val1, Val2 : Integer)
  with Ghost, Global => null,
       Pre => Val1 >= 0 and Val2 > 0,
       Post => Big (Val1 / Val2) * Big (Val2) <= Big (Val1)
               and Big (Val1) - Big (Val1 / Val2) * Big (Val2) < Big (Val2)
               and Big (Val1 / Val2) * Big (Val2) + Big (Val1 rem Val2) = Big (Val1);

a quotient and a remainder put the dividend back together

Lemma_Mult_Then_Div

procedure Lemma_Mult_Then_Div (Val1, Val2 : Integer)
  with Ghost, Global => null,
       Pre => Val2 /= 0 and then Big (Val1) * Big (Val2) in Big (Integer'First) .. Big (Integer'Last),
       Post => (Val1 * Val2) / Val2 = Val1;

Lemma_Div_Is_Smaller

procedure Lemma_Div_Is_Smaller (Val1, Val2 : Integer)
  with Ghost, Global => null,
       Pre => Val1 >= 0 and Val2 > 0,
       Post => Val1 / Val2 <= Val1;

a quotient is no larger than its dividend

Lemma_Mod_Range

procedure Lemma_Mod_Range (Val1, Val2 : Integer)
  with Ghost, Global => null,
       Pre => Val2 > 0,
       Post => Val1 mod Val2 in 0 .. Val2 - 1;

remainders and modular sums

Lemma_Mod_Of_Smaller

procedure Lemma_Mod_Of_Smaller (Val1, Val2 : Integer)
  with Ghost, Global => null,
       Pre => Val2 > 0 and then Val1 in 0 .. Val2 - 1,
       Post => Val1 mod Val2 = Val1;

Lemma_Mod_Mult

procedure Lemma_Mod_Mult (Val1, Val2 : Integer)
  with Ghost, Global => null,
       Pre => Val2 > 0 and then Big (Val1) * Big (Val2) in Big (Integer'First) .. Big (Integer'Last),
       Post => (Val1 * Val2) mod Val2 = 0;