Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
prove lemma unsigned associativity sub
Browse files Browse the repository at this point in the history
ref #50
  • Loading branch information
jklmnn authored and senier committed Jul 19, 2019
1 parent 60a8e3a commit 0ec84cf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
48 changes: 47 additions & 1 deletion src/lib/componolit-runtime-conversions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,52 @@ is
end if;
end Lemma_Uns_Associativity_Add;

procedure Lemma_Uns_Associativity_Sub (X, Y : Int64) is null;
procedure Lemma_Uns_Associativity_Sub (X, Y : Int64)
is
begin
if X < 0 and Y < 0 then
if X = Int64'First and Y = Int64'First then
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
elsif X = Int64'First then
pragma Assert (X - Y = X + (-Y));
pragma Assert (X - Y = To_Int (To_Uns (X) + To_Uns (-Y)));
pragma Assert (-To_Uns (Y) = To_Uns (-Y));
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
elsif Y = Int64'First then
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
else
if X >= Y then
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
else -- X < Y
pragma Assert (X - Y = X + (-Y));
pragma Assert (X - Y = To_Int (To_Uns (X) + (-To_Uns (Y))));
pragma Assert (X - Y = To_Int (To_Uns (X) + To_Uns (-Y)));
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
end if;
end if;
elsif X >= 0 and Y >= 0 then
if X >= Y then
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
else -- X < Y
pragma Assert (X - Y = -Y - (-X));
pragma Assert (X - Y = -Y + X);
pragma Assert (X - Y = To_Int (To_Uns (-Y) + To_Uns (X)));
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
end if;
elsif X >= 0 and Y < 0 then
if Y = Int64'First then
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
else
pragma Assert (X - Y = X + (-Y));
pragma Assert (X - Y = To_Int (To_Uns (X) + To_Uns (-Y)));
pragma Assert (X - Y = To_Int (To_Uns (X) + (-To_Uns (Y))));
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
end if;
elsif X < 0 and Y >= 0 then
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
else
pragma Assert (X - Y = To_Int (To_Uns (X) - To_Uns (Y)));
end if;
end Lemma_Uns_Associativity_Sub;

end Componolit.Runtime.Conversions;
4 changes: 1 addition & 3 deletions src/lib/componolit-runtime-conversions.ads
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ is
Pre => (if X >= 0 and Y <= 0 then Y > Int64'First
and then Int64'Last - X >= abs (Y))
and (if X < 0 and Y > 0 then Y < Int64'First - X),
Post => X - Y = To_Int (To_Uns (X) - To_Uns (Y)),
Annotate => (GNATprove, False_Positive, "postcondition",
"subtraction in 2 complement is associative");
Post => X - Y = To_Int (To_Uns (X) - To_Uns (Y));

end Componolit.Runtime.Conversions;

0 comments on commit 0ec84cf

Please sign in to comment.