comp.lang.ada
 help / color / mirror / Atom feed
* Proving A Loop will Terminate in SPARK Question
@ 2017-03-08 21:25 bakolden5
  2017-03-09 15:13 ` Phil Thornley
  0 siblings, 1 reply; 2+ messages in thread
From: bakolden5 @ 2017-03-08 21:25 UTC (permalink / raw)


I got my hands on "Building High Integrity Applications with SPARK" and wanted to do some tests with loop proofs. I quickly ran into a case that I did not know how to verify.

	procedure Test is
		type Big is mod 2**16;
		I : Big := 1;
	begin
		while I /= 0 loop
			I := 2**Natural(I);
		end loop;
	end Test;

Theoretically, this loop will end however if the condition was I /= 256, it will not. Is it possible to check if I will reach the condition, given a specific starting value of I (1, in this case)?


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

* Re: Proving A Loop will Terminate in SPARK Question
  2017-03-08 21:25 Proving A Loop will Terminate in SPARK Question bakolden5
@ 2017-03-09 15:13 ` Phil Thornley
  0 siblings, 0 replies; 2+ messages in thread
From: Phil Thornley @ 2017-03-09 15:13 UTC (permalink / raw)


On Wednesday, March 8, 2017 at 9:25:29 PM UTC, Brian Kolden wrote:
> I got my hands on "Building High Integrity Applications with SPARK" and wanted to do some tests with loop proofs. I quickly ran into a case that I did not know how to verify.
> 
> 	procedure Test is
> 		type Big is mod 2**16;
> 		I : Big := 1;
> 	begin
> 		while I /= 0 loop
> 			I := 2**Natural(I);
> 		end loop;
> 	end Test;
> 
> Theoretically, this loop will end however if the condition was I /= 256, it will not. Is it possible to check if I will reach the condition, given a specific starting value of I (1, in this case)?

This isn't really a good example of how to use SPARK. The procedure has no inputs and has no external effect other than either terminating or running for ever, so has no meaningful contract.

In practice SPARK is mostly about creating contracts for subprograms, and the various proof pragmas inserted into the code, such as Loop_Invariant, are there to support the proof that the code meets its contract.

If I had to write a loop invariant for this code I would start with something like:
I = 1 or I = 2 or I = 4 or I = 16

Cheers,

Phil Thornley

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

end of thread, other threads:[~2017-03-09 15:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-08 21:25 Proving A Loop will Terminate in SPARK Question bakolden5
2017-03-09 15:13 ` Phil Thornley

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