Advertisement
Guest User

Untitled

a guest
May 3rd, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.03 KB | None | 0 0
  1. package body Max with SPARK_Mode
  2. is
  3. function FindMax2 (V : Vector) return Integer
  4.    is
  5.       SecondMax : Natural := 0;
  6.       Max : Natural := 0;
  7.    begin
  8.                
  9.       for I in V'Range loop
  10.          if V(I) > Max then
  11.             SecondMax := Max;
  12.             Max := V(I);
  13.          elsif V(I) > SecondMax and V(I) < Max then
  14.             SecondMax := V(I);
  15.          end if;
  16.  
  17.          pragma Loop_Invariant (for all J in V'First .. I => V(J) <= Max);
  18.          pragma Loop_Invariant (for some J in V'First .. I => V(J) = Max);
  19.          pragma Loop_Invariant (if SecondMax = 0 then (for all J in V'First .. I => V(J) = Max));
  20.          pragma Loop_Invariant (if SecondMax /= 0 then (for some  J in V'First .. I => V(J) = SecondMax));
  21.          pragma Loop_Invariant (if SecondMax /= 0 then (for some  J in V'First .. I => V(J) > SecondMax));
  22.          pragma Loop_Invariant (for all K in V'First .. I => (if V(K) > SecondMax then V(K) = Max));  
  23.  
  24.       end loop;
  25.  
  26.       return SecondMax;
  27. end FindMax2;
  28.    
  29.  
  30. end Max;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement