comp.lang.ada
 help / color / mirror / Atom feed
From: phil.clayton@lineone.net
Subject: Re: SPARK problem with unconstrained arrays
Date: Tue, 24 Mar 2015 16:03:36 -0700 (PDT)
Date: 2015-03-24T16:03:36-07:00	[thread overview]
Message-ID: <ce003d5d-a850-4378-8a26-853a261e9aee@googlegroups.com> (raw)
In-Reply-To: <00de73ba-0430-4528-9f10-cf664a70fa02@googlegroups.com>

On Tuesday, 3 March 2015 09:41:35 UTC, Maciej Sobczak  wrote:
> After some exploration I can answer my own question: empty slices.
> 
> Solution: add precondition to the Find_Min procedure:
> 
>     procedure Find_Min (A : in My_Array; I : out Index)
>         with Pre => A'First <= A'Last,
>              -- ...

Interestingly, this precondition was known to be necessary before your package body even existed: in the postcondition, there is no way that the predicate
  I in A'Range
could be satisfied if A is empty (and A does not change because it is an 'in' parameter).

There is a theoretical method for determining a 'minimum' precondition of a specification - that is, the condition under which the specification is achievable.  Just existentially quantify over the 'changed' variables, in your case I:

  ∃ I : Index ⦁
    I ∈ A'Range ∧
      (∀ J : A'Range ⦁ A (I) ≤ A (J)) 

That's a predicate whose only free variable is A, so it says something about A.  Unfortunately, it's not obvious what.  That's probably equivalent to A is not empty in the context of A : My_Array.  In one direction the proof is trivial but in the other, you probably have to start by showing that a non-empty set of integers has a least element...  It's this sort of thing that gave formal methods a bad name.

Phil


      parent reply	other threads:[~2015-03-24 23:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-03  9:29 SPARK problem with unconstrained arrays Maciej Sobczak
2015-03-03  9:41 ` Maciej Sobczak
2015-03-04 21:31   ` Jacob Sparre Andersen
2015-03-04 22:31     ` Maciej Sobczak
2015-03-13 22:15       ` Shark8
2015-03-24 23:03   ` phil.clayton [this message]
replies disabled

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