Software Evolution by Correctness Enhancement
Software Evolution by Correctness Enhancement
• Two relations admit a least upper bound if and only In the same way that refinement provides a formal model for
if they satisfy the following condition, which we call program derivation, relative correctness, as defined herein,
the consistency condition: RL ∩ R′ L = (R ∩ R′ )L. provides a formal model for fault removal; see Figure 3 (a).
To give the reader some confidence in the soundness of our
• Whenever two relations R and R′ do satisfy the con- definition of relative correctness, we present the following
sistency condition, their least upper bound (join) is properties, due to [13]:
defined by: R ⊔ R′ = R′ L ∩ R ∪ RL ∩ R′ ∪ (R ∩ R′ ).
• Relative correctness is reflexive and transitive, but not
• Two relations have a least upper bound if and only if antisymmetric.
they have an upper bound.
• Relative correctness culminates in (absolute) correct-
ness, i.e. a correct program is more-correct than (or
3. RELATIVE CORRECTNESS as correct as) any candidate program.
The reader can check (by referring to the definition of re- Attribute Refinement Based Based on Relative
finement given in section 2 and by Proposition 1) that p1 is Correctness
more-correct than p0 but does not refine it, whereas p2 re- Initialization a=R a = abort
fines p0 hence (according to Proposition 2) is more-correct Invariant a is correct a is a program
than p0. We have a simple explanation for this observa- Assertion
tion: if we consider the functional attributes of p0, we can a increasingly conc-
Variant a increasingly
distinguish between two sources of information:
Function rete (program-like) correct
• Functional attributes that are mandated by the spec- Exit test when a is a program when a is correct
ification, such as the clause {x′ = x + y} in P0 .
• Functional attributes that are not mandated by the Figure 2: Iterative Paradigms of Programming
specification, but stem from design decisions, such as
the clause {y ′ = 0} in P0 .
reliability; hence the successive programs generated by this
In order for a program to refine P0 , it has to preserve all process are increasingly reliable; so that the derivation of
the functional attributes of P0 , regardless of their origin a reliable program proceeds in the same way as the deriva-
(specification or design); this is the case for p2. But in order tion of a correct program, except that it terminates as soon
for a program to be more-correct than P0 , it suffices for as the reliability reaches or exceeds the required threshold.
it to preserve the functional attributes that are mandated Given that correctness is the culmination of reliability, it
by R; it may, in the process, override / alter functional is only fitting that the derivation of a correct program be
attributes that stem from design decisions; this is the case the culmination of the derivation of a reliable program. See
for program p1 which overrides {y ′ = 0} with {y ′ = y}. Not Figures 3 (b) and (c).
surprisingly, p1 is simpler than p2, because it is subject to
a less stringent condition.
5. PROGRAM MERGER
4. PROGRAM DERIVATION We consider a specification R and two candidate pro-
grams P1 and P2 (i.e. programs that are written to satisfy
4.1 Correct Programs R –they may or may not satisfy it in fact), each of which
fulfills the requirements of R to some limited extent, but not
To derive a correct program for a specification R, we
necessarily to the full extent. We are interested to merge
have to find an artifact that has two properties: it is a (ex-
programs P1 and P2 into a program that fulfills the require-
ecutable) program; and it is correct with respect to R. To
ments of R to the extent that P1 fulfills them, and to the
do this in a stepwise manner, we can either preserve correct-
extent that P2 fulfills them. We submit the following defi-
ness until we achieve executability (this is the traditional
nition.
refinement-based process), or we can maintain executability
until we achieve correctness (as we advocate in [4]). These Definition 3. Given a specification R and two candi-
two processes being iterative, we can characterize them by date programs P1 and P2 , a merger of P1 and P2 with re-
their initial state, their invariant assertion, their variant spect to R is any program P ′ that is more-correct than P1
function, and their exit condition, as shown in Figure 2. and more-correct than P2 with respect to R.
See also Figure 3 (b).
We mandate that a merger program be merely more-
4.2 Reliable Programs correct than programs P1 and P2 , rather than to refine
In many applications, correctness is unnecessary, and the them, for the following reasons:
cost of achieving correctness (as opposed to sufficient reli-
ability) may be unjustified by the stakes attached to (suffi- • Refinement is Unnecessary. When we resolve to re-
ciently infrequent) program failure. In such cases, it may be fine a program, we commit to refine all its functional
sufficient to produce a reliable program, rather than a cor- attributes, those that are mandated by the specifica-
rect program. Thankfully, the derivation model presented tion as well as those that stem from design decisions.
herein encompasses the derivation of reliable programs as But we have no reason to preserve design decisions of
well as the derivation of correct programs: as we remember P1 and P2 that do not advance the cause of relative
from section 3, relative correctness logically implies higher correctness.
abort abort
Specifi- Specifi- Specifi-
cation R cation R cation R
Imperfect
⊑R A ⊑R A
Design ⊑ Initialization ⊑ Initialization ⊑
A ⊑RA
)
⊑ ⊑R
A ⊑ A ⊑
Incorrect ⊑R A ⊑R A
U
A
Program P ⊑ ⊑ ⊑
Reliable
H ⊑R
⊑R HH ?⊑ AU ?⊑
Program P ′′
?⊑
Monotonic ⊑R HH
j Correct Correct Correct
Fault ⊑R Program P ′ Program P ′ Program P ′
Removal
(b)
(a) (c)
Program Derivation
A Framework for Fault Removal Deriving Reliable Programs
by Correctness Enhancement
B@ @
B@ @
⊒R B @ ⊒R ⊒R @⊒
B @ @
⊒ B⊒ @ ⊒ @
P1• B @• P2 P1• @• Q
@ B @
@
⊒ B ⊒ ⊒@
@• B• @•
R1 R2 R1
(a) (b)
Merger of P1 and P2 Upgrading P1 with Feature Q