comp.lang.ada
 help / color / mirror / Atom feed
* SPARK - divide algorithm issue
@ 2013-04-19 21:33 Maciej Sobczak
  2013-04-20  9:02 ` Phil Thornley
  0 siblings, 1 reply; 3+ messages in thread
From: Maciej Sobczak @ 2013-04-19 21:33 UTC (permalink / raw)


Playing further with implementing division in SPARK, but this time an example from John Barnes book is causing problems:

    procedure Divide (M, N : in Integer; Q, R : out Integer);
    --# derives Q, R from M, N;
    --# pre M >= 0 and N > 0;
    --# post (M = Q * N + R) and (R < N) and R >= 0;

    procedure Divide (M, N : in Integer; Q, R : out Integer) is
    begin
        Q := 0;
        R := M;
        loop
            --# assert M = Q * N + R and R >= 0;
            exit when R < N;
            Q := Q + 1;   -- here
            R := R - N;
        end loop;
    end Divide;

In this example SPARK cannot prove that the marked line (Q := Q + 1) is safe with respect to Integer'Last. What is most frustrating is that this is a book example, where it is claimed to verify OK.
Is it possible that in the meantime there were changes in the toolchain that caused this to stop working?
If yes, what would be the proper strategy to hint the prover that the loop will never run longer than the range of positive values?

(This example looks nicer with Natural and Positive types used where appropriate, but I wanted to make it as close to the original as possible.)

Again, this is SPARK GPL 2011.

-- 
Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-04-22  7:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-19 21:33 SPARK - divide algorithm issue Maciej Sobczak
2013-04-20  9:02 ` Phil Thornley
2013-04-22  7:50   ` Maciej Sobczak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox