comp.lang.ada
 help / color / mirror / Atom feed
* loop variant in SPARK ADA
@ 2005-09-19  9:25 Constantin Porphyrogenete
  2005-09-19 13:23 ` Jacob Sparre Andersen
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Constantin Porphyrogenete @ 2005-09-19  9:25 UTC (permalink / raw)


Couldn't find the newsgroup for SPARK.
Thought I'd try this one.

Read the book. It seems there is no
way to assert a loop variant to
help prove termination (I am thinking
of the Eiffel loop variant).

Is there any reason SPARK ADA doesn't
have this?




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

* Re: loop variant in SPARK ADA
  2005-09-19  9:25 loop variant in SPARK ADA Constantin Porphyrogenete
@ 2005-09-19 13:23 ` Jacob Sparre Andersen
  2005-09-19 15:40 ` Jeffrey Carter
  2005-09-20 17:15 ` Rod Chapman
  2 siblings, 0 replies; 9+ messages in thread
From: Jacob Sparre Andersen @ 2005-09-19 13:23 UTC (permalink / raw)


Constantin Porphyrogenete wrote:

> Couldn't find the newsgroup for SPARK.  Thought I'd try this one.

I think it is the appropriate newsgroup for SPARK questions, even if
it isn't mentioned explicitly in the charter.

> Read the book. It seems there is no way to assert a loop variant to
> help prove termination (I am thinking of the Eiffel loop variant).
>
> Is there any reason SPARK ADA doesn't have this?

I'm tempted to quote Larry Wall on this subject (altough he's talking
about Ada and not SPARK):

  "I remember being impressed with Ada because you could write an
   infinite loop without a faked up condition. The idea being that in
   Ada the typical infinite loop would normally be terminated by
   detonation."

Being more serious; I don't know why the designers of SPARK have made
that decision.

Greetings,

Jacob
-- 
"The point is that I am now a perfectly safe penguin!"




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

* Re: loop variant in SPARK ADA
  2005-09-19  9:25 loop variant in SPARK ADA Constantin Porphyrogenete
  2005-09-19 13:23 ` Jacob Sparre Andersen
@ 2005-09-19 15:40 ` Jeffrey Carter
  2005-09-19 16:03   ` Georg Bauhaus
  2005-09-20 17:15 ` Rod Chapman
  2 siblings, 1 reply; 9+ messages in thread
From: Jeffrey Carter @ 2005-09-19 15:40 UTC (permalink / raw)


Constantin Porphyrogenete wrote:
> Couldn't find the newsgroup for SPARK.
> Thought I'd try this one.

SPARK discussions have been welcome here in the past. I hope that won't 
be changing soon.

> Read the book. It seems there is no
> way to assert a loop variant to
> help prove termination (I am thinking
> of the Eiffel loop variant).

Presumably you mean a loop invariant?

> Is there any reason SPARK ADA doesn't
> have this?

I don't have the book to hand, but I do have the SPARK Quick Reference 1:

"The _/assert annotation/_ can be used to specify conditions that are to 
be true - of particular use when verifying programs containing loops."

There is then an example of a Div procedure to calculate M/N, giving the 
quotient in Q and the remainder in R. The loop invariant is:

--# assert (M = Q * N + R) and (R >= 0);

-- 
Jeffrey Carter
"Now go away or I shall taunt you a second time."
Monty Python and the Holy Grail
E-mail: jeffrey_r_carter-nr [commercial-at]
         raytheon [period | full stop] com



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

* Re: loop variant in SPARK ADA
  2005-09-19 15:40 ` Jeffrey Carter
@ 2005-09-19 16:03   ` Georg Bauhaus
  2005-09-19 22:22     ` Jeffrey Carter
  0 siblings, 1 reply; 9+ messages in thread
From: Georg Bauhaus @ 2005-09-19 16:03 UTC (permalink / raw)


Jeffrey Carter wrote:

>> Read the book. It seems there is no
>> way to assert a loop variant to
>> help prove termination (I am thinking
>> of the Eiffel loop variant).
> 
> 
> Presumably you mean a loop invariant?

Eiffel does have both an invariant and a variant in its loop,

from ...
invariant
  invariant_name: cond
variant
  variant_name: int_var   -- expr >= 0, decreasing
until cond
loop
 ...
end loop




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

* Re: loop variant in SPARK ADA
  2005-09-19 16:03   ` Georg Bauhaus
@ 2005-09-19 22:22     ` Jeffrey Carter
  2005-09-20  8:17       ` Georg Bauhaus
  0 siblings, 1 reply; 9+ messages in thread
From: Jeffrey Carter @ 2005-09-19 22:22 UTC (permalink / raw)


Georg Bauhaus wrote:
> 
> Eiffel does have both an invariant and a variant in its loop,
> 
> from ...
> invariant
>  invariant_name: cond
> variant
>  variant_name: int_var   -- expr >= 0, decreasing
> until cond
> loop
> ...
> end loop

I see. Does this mean you can't write infinite loops in Eiffel?

-- 
Jeffrey Carter
"Now go away or I shall taunt you a second time."
Monty Python and the Holy Grail
E-mail: jeffrey_r_carter-nr [commercial-at]
         raytheon [period | full stop] com



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

* Re: loop variant in SPARK ADA
  2005-09-19 22:22     ` Jeffrey Carter
@ 2005-09-20  8:17       ` Georg Bauhaus
  0 siblings, 0 replies; 9+ messages in thread
From: Georg Bauhaus @ 2005-09-20  8:17 UTC (permalink / raw)


Jeffrey Carter wrote:
>  Does this mean you can't write infinite loops in Eiffel?

For sure you can write infinite loops, there is no requirement in the
language that force termination. A variant (or an invariant) need not
be given.

    possibly_infinite_loop(eternity: BOOLEAN) is 
        -- one way to write an infinite loop
      do
        from until eternity loop
          do_it_again
        end
      end



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

* Re: loop variant in SPARK ADA
  2005-09-19  9:25 loop variant in SPARK ADA Constantin Porphyrogenete
  2005-09-19 13:23 ` Jacob Sparre Andersen
  2005-09-19 15:40 ` Jeffrey Carter
@ 2005-09-20 17:15 ` Rod Chapman
  2005-09-21  2:49   ` Constantin Porphyrogenete
  2 siblings, 1 reply; 9+ messages in thread
From: Rod Chapman @ 2005-09-20 17:15 UTC (permalink / raw)


SPARK doesn't directly support the specificaciton of _variants_
for loops at present.

It's something we've often thought about, but no paying customer
has ever asked us for!  We also find that, in most embedded, critical
systems, the loop structures used are so simple that establishing
their termination is hardly ever a big problem.

- Rod Chapman, SPARK Team, Praxis




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

* Re: loop variant in SPARK ADA
  2005-09-20 17:15 ` Rod Chapman
@ 2005-09-21  2:49   ` Constantin Porphyrogenete
  2005-09-21 17:31     ` Jeffrey Carter
  0 siblings, 1 reply; 9+ messages in thread
From: Constantin Porphyrogenete @ 2005-09-21  2:49 UTC (permalink / raw)


Thanks for the reply.

The reason for my asking was puzzlement over part of a paragraph
in the book on page 72

"Nevertheless, it is all too easy to
forget to think about the problem of termination and
to conclude that a subprogram is correct just because
all the verification conditions are true."

The impression that I got from the book was that the
point of tools like the Examiner and Simplifier was
precisely to prevent this sort of carelessness.

But I guess it is not to difficult to translate a loop variant
into a loop invariant with the help of some extra variables.

Thanks again for the reply.




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

* Re: loop variant in SPARK ADA
  2005-09-21  2:49   ` Constantin Porphyrogenete
@ 2005-09-21 17:31     ` Jeffrey Carter
  0 siblings, 0 replies; 9+ messages in thread
From: Jeffrey Carter @ 2005-09-21 17:31 UTC (permalink / raw)


Constantin Porphyrogenete wrote:
> 
> "Nevertheless, it is all too easy to
> forget to think about the problem of termination and
> to conclude that a subprogram is correct just because
> all the verification conditions are true."

I suspect this refers to the general concept of correctness proofs. The 
correctness proofs in SPARK are technically incomplete proofs because 
they don't prove termination in general; in other words, they haven't 
solved the halting problem.

-- 
Jeffrey Carter
"Now go away or I shall taunt you a second time."
Monty Python and the Holy Grail
E-mail: jeffrey_r_carter-nr [commercial-at]
         raytheon [period | full stop] com



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

end of thread, other threads:[~2005-09-21 17:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-19  9:25 loop variant in SPARK ADA Constantin Porphyrogenete
2005-09-19 13:23 ` Jacob Sparre Andersen
2005-09-19 15:40 ` Jeffrey Carter
2005-09-19 16:03   ` Georg Bauhaus
2005-09-19 22:22     ` Jeffrey Carter
2005-09-20  8:17       ` Georg Bauhaus
2005-09-20 17:15 ` Rod Chapman
2005-09-21  2:49   ` Constantin Porphyrogenete
2005-09-21 17:31     ` Jeffrey Carter

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