Projecting Programs On Specifications Definition and Implications
Projecting Programs On Specifications Definition and Implications
Jules Desharnais
Département d’Informatique, Université Laval, Québec, Canada
[email protected]
Nafi Diallo
New Jersey Institute of Technology, Newark, NJ
[email protected]
Wided Ghardallou
Faculté des Sciences de Tunis, El Manar, Tunisia
[email protected]
Ali Mili
New Jersey Institute of Technology, Newark, NJ
[email protected]
Abstract
2
the property of a program to be more-correct than another with respect to a
specification. Relative correctness, due to Desharnais et al. (2015), is discussed
in section 3. In section 2 we introduce the mathematical background that we
use throughout this paper. In section 6 we ibriefly summarize and assess our
work, then compare it to related research.
2 Mathematical Background
3
erator precedence is adopted as follows: unary operators apply first, followed
by product, then intersection, then union.
4
RL
= {hypothesis}
RL ∩ R L ∩ (R ∪ R′ )L
′
= {distributivity, associativity}
(RL ∩ R L) ∩ (RL ∪ R′ L)
′
= {since RL ⊆ R′ L}
RL ∩ R′ L ∩ (R ∪ R′ )
= {hypothesis}
R. qed
We find in Boudriga et al. (1992) that the refinement relation is reflexive, anti-
symmetric and transitive, and that it has the following lattice-like properties:
• Any two relations R and R′ have a greatest lower bound, which we denote
by R ⊓ R′ and to which we refer as the meet of R and R′ . Also, we find:
R ⊓ R′ = RL ∩ R′ L ∩ (R ∪ R′ ).
• Two relations R and R′ admit a least upper bound if and only if they satisfy
the condition RL∩R′ L = (R∩R′ )L, which we call the consistency condition.
• Any two relations that satisfy the consistency condition admit a least upper
bound, which we denote by R ⊔ R′ and to which we refer as the join of R
and R′ . Also, we find:
R ⊔ R′ = (RL ∩ R′ ) ∪ (R′ L ∩ R) ∪ (R ∩ R′ ).
5
• The empty relation is the universal lower bound of this ordering.
• This ordering admits no universal upper bound. Total deterministic rela-
tions are the maximal elements of this ordering.
• Abort: [abort] ≡ φ.
• Skip: [skip] ≡ I.
• Assignment: [s = E(s)] ≡ {(s, s′ )|s ∈ δ(E) ∧ s′ = E(s)}, where δ(E) is the
set of states for which expression E can be evaluated.
• Sequence: [p1 ; p2 ] ≡ [p1 ] ◦ [p2 ].
• Conditional: [if (t) {p}] ≡ T ∩ [p] ∪ T ∩ I, where T is the vector defined as:
T = {(s, s′)|t(s)}.
• Alternation: [if (t) {p} else {q}] ≡ T ∩ [p] ∪ T ∩ [q], where T is defined as
above.
• Iteration: [while (t) {b}] ≡ (T ∩ [b])∗ ∩ Tb , where T is defined as above.
• Block: [{x : X; p}] ≡ {(s, s′ )|∃x, x′ ∈ X : (hs, xi, hs′ , x′ i) ∈ [p]}.
Rather than use the notation [p] to denote the function of program p, we will
usually use upper case P as a shorthand for [p]. By abuse of notation, we may,
when it causes no confusion, refer to a program and its function by the same
name (which we represent by an upper case letter).
6
3.2 Absolute Correctness
7
R P P′
0 : 0 0 XXX 0 0 :
0
XX
XXX
z 1
1 XXX
: 1 1 XXX 1 :
1
X
X
X XX
XXX
XXz z
2 XXX
: 2 X
2 XX 2 2 :
2
X
XXX XX
XXX
Xz z
3 XXX
: 3 3 XXX 3 3 :
3
X
X
X XX
XXX
XXz z
4 XXX
: 4 4 XXX 4 4 :
4
X
XXX XX
XXX
Xz 5 XXX z 5
:
5 5 5 5
XX
XXX
6 6 6 z 6
6 6
Fig. 1. Enhancing correctness without duplicating behavior: P′ ⊒R P
R = {(s, s′)|s2 ≤ s′ ≤ s3 },
and we consider the following programs, where along with each program we
indicate its function, then its competence domain with respect to R:
Figure 2 shows how these ten programs are ordered according to their relative
correctness with respect to R; in this sample, programs P7 , P8 , P9 are (abso-
lutely) correct while programs P0 , P1 , P2 , P3 , P4 , P5 , P6 are incorrect because
8
P7 , P8 , P9
@
@
@
@
@
@
@
@ @
P6 @ @
@ @P
P4 @ 5
@
@ @
@ @
@ @
@ @
@ @
P1 @P
@ @ 3
@ @ P2
@ @
@ @
@
@
@
@
@
@
P0
Fig. 2. Ordering Candidate Programs by Relative Correctness
their competence domain is strictly smaller than the domain of R.
(R ∩ P )L ⊆ (R ∩ P ′ )L ∧
9
0 XXX R - P P′
X
X
:0 H
0Z
HH *
0 H
0Z
H
*
0
XXXX Z ZHH
X
z ZHH Z
1 XX -
:1 1ZH ZH :
1 1XHXX H
ZHH 1
X
X H H
Z
*
>
HXX
ZX*
XXXX
ZH
H
Z H
j H
H XHj
H
2X z
- 2 ZHH 2XX HZZXX
z
XX
XX:2
Z
H
Z
H
:
*
2 XH
XXXH*
2
ZZ Z
XXXX
H>
~
Z
Z H
j X
H
>
~
Z
j
H
XX
3 XXX
z
-
3XX
z
XX:3
3 Z *
ZZ
3 X
XX *
3
XXXX
z
~ XX
XX
z
4 XXX - 4 XX
X
X
:4 4
4 X
XXX
4
XXXX
X
z
- XX
z
5 5 5 5 5 5
Fig. 3. Relative Correctness for Non-Deterministic Programs: P ′ ⊒R P .
(R ∩ P )L ∩ R ∩ P ′ ⊆ P.
(5, 3)}
From these definitions, we compute:
R ∩ P = {(2, 1), (3, 2)},
(R ∩ P )L = {2, 3} × S,
R ∩ P ′ = {(1, 2), (2, 3), (3, 4), (4, 5)}
(R ∩ P ′)L = {1, 2, 3, 4} × S
(R ∩ P )L ∩ P ′ = {(2, 0), (2, 3), (3, 1), (3, 4)}
(R ∩ P )L ∩ R ∩ P ′ = {(2, 0), (3, 1)}
By inspection, we do find that (R ∩ P )L = {2, 3} × S is indeed a subset of
(R∩P ′ )L = {1, 2, 3, 4}×S. Also, we find that (R∩P )L∩R∩P ′ = {(2, 0), (3, 1)}
is a subset of P . Hence the two clauses of Definition 4 are satisfied. Figure
3 represents relations R, P and P ′ on space S. Program P ′ is more-correct
than program P with respect to R because it has a larger competence domain
({2, 3} vs. {1, 2, 3, 4}, highlighted in Figure 3) and because on the competence
domain of P (={2, 3}), program P ′ generates no incorrect output unless P
also generates it ({(2, 0), (3, 1)}).
10
3.5 Equal Correctness
(P ≡R P ′ ) ⇔ (R ∩ P )L = (R ∩ P ′ )L ∧ (R ∩ P )L ∩ R ∩ P = (R ∩ P ′ )L ∩ R ∩ P ′ .
Proof. From P ≡R P ′ we infer readily that P and P ′ have the same com-
petence domain with respect to R. Also, from (R ∩ P )L ∩ R ∩ P ′ ⊆ P and
(R ∩ P )L = (R ∩ P ′ )L we infer:
(R ∩ P ′ )L ∩ R ∩ P ′ ⊆ (R ∩ P )L ∩ R ∩ P.
(R ∩ P ′ )L ∩ R ∩ P ′ = (R ∩ P )L ∩ R ∩ P.
11
The converse implication is trivial, if we replace equality by inclusion, and
note that an intersection is a subset of its terms. qed
4.1 Definition
ΠR (P ) = (R ∩ P )L ∩ (R ∪ P ).
Proof. ΠR (ΠR (P ))
= {Definition of ΠR }
(R ∩ ΠR (P ))L ∩ (R ∪ ΠR )
= {Definition of ΠR }
(R ∩ (R ∩ P )L ∩ (R ∪ P ))L ∩ (R ∪ (R ∩ P )L ∩ (R ∪ P ))
= {Boolean algebra}
((R ∩ P )L ∩ R)L ∩ (R ∪ (R ∩ P )L ∩ P )
= {(QL ∩ R)L = QL ∩ RL}
(R ∩ P )L ∩ RL ∩ (R ∪ (R ∩ P )L ∩ P )
= {Monotonicity of composition and Boolean algebra}
(R ∩ P )L ∩ (R ∪ (R ∩ P )L ∩ P )
= {Boolean algebra}
(R ∩ P )L ∩ (R ∪ P )
= {Definition of ΠR }
ΠR (P ) qed
12
Proof. Let π be the projection of P on R; according to Proposition 1, we
have to prove πL ⊆ RL and πL ∩ R ⊆ π. The first clause stems readily from
πL = (R ∩ P )L by monotonicity. The second clause can be proved as follows:
πL ∩ R
= {πL = (R ∩ P )L}
(R ∩ P )L ∩ R
⊆ {monotonicity}
(R ∩ P )L ∩ (R ∪ P )
= {substitution}
π. qed
Whereas P and P ′ may fail to have a join (due to divergent designs), their
projections on R may not (since they only reflect subspecifications of R).
13
Proposition 7. Let R and P be relations on space S. Then the projection of
P over R is in the same equivalence class of ≡R as P .
14
R P P′
0 XXX -
:0
:0
0HZH 0 0H
X
X
XX ZHH
@H
H
X-
z
X Z H @H
1XXX :1
1XHX Z H
-1 1 -
HH@ HH
:1
X
X HXX X
Z H H
XXX HH XXXHH H@ H
z
X
- Z j
z
X
-
H@ j
H
X
2 XX :2
2XHX HHZ 2 2HH HH
-
:2
X
X HXXX HZ
@HH
XXX HH XXXH> HH
z
X
-
~
Z
j
H
X
z
H - H
j
H
@ -
X
3 XX :3
3XHX 3 3H :
3
X
X HXXXH
HH* H H
@
H
*
R
@
XXX HHXX H H
z
X
-
Xj
H
z
X
-
H
H
j
H
-
X
4 XX :4
4XXXH H 4 4 4
X
X
X HH H
HH
XXX XXXX
j
H
j
H
z
X
- z
X
5 5 5 5 5 5
ΠR (P ) = ΠR (P ′ )
0 :0
1X
HX -
:1
HXXX
H
XX
HH X-
z
X
2X
HX H
:2
HXX H
HXX HH
HH XX-j
z
X
3X
HX X H:
3
H XXHH
H
H XXXX
j
H
4X
XXXHH
z
- 4
XXHH
XXX
j
H
z
5 5
Fig. 4. Equal Correctness of Non-Deterministic Programs: P ′ ≡R P .
Because all the programs that are equally correct map to the same projec-
tion, one would expect that relative correctness is determined by considering
projections. This is confirmed by the following proposition.
15
⇔ {A ⊆ B ⇔ (A ∩ B = A)}
(R ∩ P )L ⊆ (R ∩ P ′ )L ∧ (R ∩ P )L ∩ (R ∪ P ′) ⊆ (R ∩ P )L ∩ (R ∪ P )
⇔ {(A ∩ B ⊆ A ∩ C) ⇔ (A ∩ B ⊆ C)}
(R ∩ P )L ⊆ (R ∩ P ′ )L ∧ (R ∩ P )L ∩ (R ∪ P ′) ⊆ R ∪ P
⇔ {Shunting, and Boolean algebra}
(R ∩ P )L ⊆ (R ∩ P ′ )L ∧ (R ∩ P )L ∩ P ′ ∩ R ⊆ P
⇔ {Substitution}
P ⊒R P .
′
qed
true
⇔ {Assumption}
RL ∩ P ⊆ R
⇔ {Boolean algebra}
RL ∩ P ⊆ R ∩ P
⇒ {Monotonicity of composition}
(RL ∩ P )L ⊆ (R ∩ P )L
⇔ {(QL ∩ R)L = QL ∩ RL}
RL ∩ P L ⊆ (R ∩ P )L
⇔ {Assumption RL ⊆ P L and Boolean algebra}
RL ⊆ (R ∩ P )L
⇔ {Boolean algebra, monotonicity of composition}
RL = (R ∩ P )L
ΠR (P )
= {Definition of ΠR }
(R ∩ P )L ∩ (R ∪ P )
16
R, P arbitrary P partially correct wrt R P (totally) correct wrt R
R P R P P
• • • • •
A@ @
A@ @
A @ @
A @ @
A @• @•
A R⊓P R ⊓ P = ΠR (P )
A
A
A
A• •
ΠR (P ) R = R ⊓ P = ΠR (P )
= {Previous proof}
RL ∩ (R ∪ P )
= {Boolean algebra and R ⊆ RL}
R ∪ RL ∩ P
= {Assumption RL ∩ P ⊆ R and Boolean algebra}
R
qed
Figure 5 captures the result of this Proposition, along with that of Corollary
2 in graphic form. The chart on the left shows the configuration of a specifi-
cation R and a candidate program P when they are unrelated; in that case,
according to Corollary 2, the meet of R and P refines the projection of P on
R. The chart in the middle shows the configuration of R and P when they
meet the consistency condition; for a deterministic program P , the consis-
tency condition means that P is partially correct with respect to R; in that
case, according to Corollary 2, the meet of R and P and the projection of P
over R are identical. The chart on the right represents the configuration of a
specification R and a program P where the program P is correct with respect
to the specification; in that case, according to Proposition 10, the projection
of P over R is equal to R, and according to the definition of refinement, the
meet of P and R is equal to R. In this figure, refinement is represented by
height (higher relations are more refined than lower relations).
17
66
R D
-
6 E
Equivalence class,
modulo ≡R
ΠR (P ) P
all the properties listed above and justifies why we called it thus. Imagine a
horseboating arrangement whereby we want to pull a barge along a canal, and
to this effect we enlist a horse to walk on a path along the canal; let R be the
acceleration that we want to apply to the barge and let P be the acceleration
that the horse applies to the cable that connects it to the barge. Then P can
be decomposed into two components: the projection of P over the axis of the
canal, which represents the useful acceleration that will drive the barge; and
the orthogonal acceleration, which serves no purpose as far as accelerating
the barge, but is a byproduct of the horseboating design. We argue that the
projection of a program on a specification represents the same concept, namely
the functionality of P that is relevant to R (i.e. that contributes to meeting
requirements of R). See Figure 6; vector E represents the excess function of P
(i.e. functional features offered by P but irrelevant for the purpose of R) and
vector D represent the functional deficit of P (functionality that is required
by R but not fulfilled by P ). The oval in this figure represent programs that
are are equally correct, as they all have the same projection on R; the least
refined element of each oval is the projection (Proposition 8); farther elements
may be refinements of the projection, but they are not more-correct than the
projection.
We now consider some concrete (yet simple) programs and specifications and
discuss in what way the projection of a program on a specification is consistent
with the interpretation we make of it. We let S be the space defined by three
variables x, y and z of type integer, and we let R be the following relation/
18
specification on S:
{(s, s′)|x′ = x + y ∧ z < z ′ }.
We consider the following program on S,
= {distribution, cancellation}
19
{(s, s′ )|y ≥ 0 ∧ x′ = x + y ∧ z < z ′ }.
20
R
=ΠR (P2 )
6
6 P2
ΠR (P0 )
=ΠR (P1 )
*
6 P1 P0
ΠR (P3 ) :
6 P3
ΠR (P4 )
- P4
∩(R ∪ P4 )
= {the first term is empty, since z < z ′ ∧ z ′ = z is false}
φ.
21
Consider program P4 : even though it does some of what the specification
mandates, which is to add x and y into x, our calculations show its projection
to be the empty specification, hence P4 is as good as abort, as far as this
specification is concerned. This may sound counter-intuitive, but it is actually
consistent with the fact that our definition of relative correctness does not re-
flect how many clauses of the specification are satisfied; rather it reflects how
many initial states the program is handling correctly; and in this situation,
because the specification mandates to increase z and the program does not,
there is not a single initial state for which the program satisfies the specifica-
tion. It is possible to (re) define relative correctness in such a way as to reflect
the extent of requirements clauses that are satisfied rather than the extent of
the input domain for which the specification (as an indivisible monolith) is
satisfied; this matter is beyond the scope of this paper.
Proof of Sufficiency. The proof uses the lemma proved in the proof of Prop.
5.1 in Desharnais et al. (2015):
Pb P ⊆ I ∧ Q ⊆ P ⇒ (R ∩ P )L ∩ Q = R ∩ Q. (1)
22
Shown first: if (R ∩ P )L ∩ P is deterministic and (R ∩ P )L ∩ R ∩ P ′ ⊆ P , then
(R ∩ P )L ∩ P ′ L = (R ∩ P )L ∩ (R ∩ P ′ )L.
(R ∩ P )L ∩ R ∩ P ′ ⊆ P
⇔ {taking the intersection with (R ∩ P )L}
(R ∩ P )L ∩ R ∩ P ′ ⊆ (R ∩ P )L ∩ P
⇒ {(R ∩ P )L ∩ P is deterministic and (1) with
P := (R ∩ P )L ∩ P and Q := (R ∩ P )L ∩ R ∩ P ′ }
(R ∩ (R ∩ P )L ∩ P )L ∩ (R ∩ P )L ∩ R ∩ P ′ = R ∩ (R ∩ P )L ∩ R ∩ P ′
⇔ {}
(R ∩ P )L ∩ R ∩ P ′ = φ
⇔ {taking the domain on both sides}
(R ∩ P )L ∩ (R ∩ P ′ )L = φ
⇒ {Identity}
((R ∩ P )L ∩ (R ∩ P ′ )L) ∪ ((R ∩ P )L ∩ (R ∩ P ′ )L) = (R ∩ P )L ∩ (R ∩ P ′)L
⇔ {Set theory}
(R ∩ P )L ∩ P L = (R ∩ P )L ∩ (R ∩ P ′ )L
′
P ′ ⊒ ΠR (P )
⇔ {substitution}
P ⊒ (R ∩ P )L ∩ (R ∪ P )
′
⇔ {definition of refinement}
(R ∩ P )L ⊆ P ′ L ∧ (R ∩ P )L ∩ P ′ ⊆ (R ∩ P )L ∩ (R ∪ P )
⇒ {taking the intersection with R, simplifying}
(R ∩ P )L ⊆ P ′ L ∧ (R ∩ P )L ∩ R ∩ P ′ ⊆ P
⇒ {Boolean algebra, P is deterministic
and result above}
(R ∩ P )L ⊆ (R ∩ P )L ∩ P ′ L ∧ (R ∩ P )L ∩ P ′ L = (R ∩ P )L ∩ (R ∩ P ′)L
⇒ {substitution}
(R ∩ P )L ⊆ (R ∩ P )L ∩ (R ∩ P ′ )L
⇔ {Boolean algebra}
(R ∩ P )L ⊆ (R ∩ P ′ )L qed
23
5.2 Program Merger
The first step in deriving the merger P ′′ of P and P ′ is to compute the specifi-
cation that P ′′ must satisfy. A naive approach would be to let the specification
of the merger be the join of P and P ′ . But this approach ought to be ruled
out for several reasons:
• The join of P and P ′ may not exist; we show an example below of such a
situation.
• When the join of P and P ′ does not exist, it is usually because of an in-
compatibility between the design of P and the design of P ′ ; it is never due
to an incompatibility between specification-relevant behaviors of P and P ′ .
R = {(s, s′)|x′ = x + y ∧ z 6= z ′ }.
24
We let p and p′ be the following candidate programs on S:
p: {z=z+1; while (y!=0) {x=x+1; y=y-1;}},
p’: {z=z-1; while (y!=0) {y=y+1; x=x-1;}}.
The functions of p and p′ are, respectively:
P = {(s, s′)|y ≥ 0 ∧ x′ = x + y ∧ y ′ = 0 ∧ z ′ = z + 1}
P ′ = {(s, s′ )|y ≤ 0 ∧ x′ = x + y ∧ y ′ = 0 ∧ z ′ = z − 1}
We compute the projections of P and P ′ on specification R. We find:
ΠR (P )
= {substitution}
{(s, s )|y ≥ 0 ∧ x′ = x + y ∧ y ′ = 0 ∧ z ′ = z + 1} ◦ L
′
∩(R ∪ P )
= {taking the domain}
{(s, s )|y ≥ 0} ∩ (R ∪ P )
′
= {since P ⊆ R}
{(s, s )|y ≥ 0} ∩ R
′
= {substitution}
{(s, s′ )|y ≥ 0 ∧ x′ = x + y ∧ z ′ 6= z}.
Likewise, we find:
ΠR (P ′ )
= {substitution}
{(s, s )|y ≤ 0 ∧ x′ = x + y ∧ y ′ = 0 ∧ z ′ = z − 1} ◦ L
′
∩(R ∪ P ′ )
= {taking the domain}
{(s, s )|y ≤ 0} ∩ (R ∪ P ′ )
′
= {since P ′ ⊆ R}
{(s, s′ )|y ≤ 0} ∩ R
= {substitution}
{(s, s )|y ≤ 0 ∧ x′ = x + y ∧ z ′ 6= z}.
′
To satisfy the union of these three terms, we write the following program:
{z=z+1;
//from P, contradicts P’, but compatible with projection of P’
25
if (y>0) {while (y!=0) {x=x+1; y=y-1;}} // from P
else {while (y!=0) {y=y+1; x=x-1;}}} // from P’.
This program delivers all the functionality of P and all the functionality of
P ′ , and while it differs from P ′ in its effect on variable z, it is compatible with
the projection of P ′ over R, which is sufficient; it constitutes a merger of P
and P ′ , i.e. a program that is more-correct than P and more-correct than P ′
with respect to R.
Note that if we had tried to compute the join of P and P ′ (rather than their
projections on R), we would have failed: To check the consistency condition
between P and P ′ , we proceed as follows:
P L = {(s, s′ )|y ≥ 0}. P ′ L = {(s, s′)|y ≤ 0}.
Hence
P L ∩ P ′L = {(s, s′)|y = 0}.
On the other hand,
(P ∩ P ′ )L
= {substitution}
{(s, s )|y = 0 ∧ x′ = x + y ∧ y ′ = 0 ∧ z ′ = z + 1 ∧ z ′ = z − 1} ◦ L
′
= {contradiction, simplification}
φ◦L
= {algebra}
φ.
Because this is different from P L ∩ P ′L, we conclude that P and P ′ have
no join. But we notice that the failure to satisfy the consistency condition
does not stem from requirements mandated by R; rather it stems from design
decisions taken in P and P ′ that turned out to be irreconcilable (whereas
program P satisfies specification z 6= z ′ by incrementing z, program P ′ satisfies
it by decrementing z). So that by trying to take the join of P and P ′ , we are
trying to combine, not only specification-relevant features of P and P ′ , but
also design-based features that stem from arbitrary design decisions taken in
the process of deriving P and P ′ . Such design decisions are not only irrelevant
for our purposes, they also run the risk of creating inconsistencies between P
and P ′ that preclude us from taking their join.
We summarize:
26
5.3 Program Upgrade
27
Note that program P is not correct with respect to R, since it fails to compute
the sum of x and y into x for negative y. We now consider the specification Q
defined by:
Q = {(s, s′ )|y > y ′}.
We want to upgrade program P to satisfy specification Q without making P
less-correct with respect to R in the process. To check whether this is possible,
we need to check whether Q and ΠR (P ) satisfy the consistency condition. To
this effect, it is sufficient, though not necessary, to prove that Q and R satisfy
the consistency condition, which we can easily see, since RL, QL and (R∩Q)L
are all equal to L.
∩(R ∪ P )
= {taking the domain in the first term, simplifying the second}
{(s, s )|y ≥ 0 ∧ x′ = x + y}.
′
28
QL = L.
P L = {(s, s′ )|y ≥ 0 ∧ x′ = x + y ∧ y ′ = 0} ◦ L = {(s, s′ )|y ≥ 0}.
Hence QL ∩ P L = {(s, s′ )|y ≥ 0}. On the other hand,
(Q ∩ P )L
= {substitution}
{(s, s )|y ≥ 0 ∧ x′ = x + y ∧ y ′ = 0 ∧ y > y ′} ◦ L
′
• P = {(x, x′ )|x′ = x2 }.
• ΠR (P )
= {definition}
(R ∩ P )L ∩ (R ∪ P )
= {substitution}
{(x, x′ )|∃x′ : x < x′ ∧ x′ = x2 } ∩ (R ∪ P )
= {simplification}
{(x, x′ )|x < 0 ∨ x > 1} ∩ {(x, x′ )|x < x′ ∨ x′ = x2 }
29
= {since (x < 0 ∨ x > 1) ⇒ x < x2 }
{(x, x′ )|(x < 0 ∨ x > 1) ∧ x < x′ }.
30
6 Conclusion
6.1 Summary
31
the functional attributes of each, but rather to combine the projections of
the programs on the specification. By focusing on projections rather than on
the original program, we ensure that we only deal with relevant information
(i.e. information that pertains to the specification, rather than information
that stems from design decisions), we ensure that we deal with minimal
specifications (that are easier to solve), and we ensure that the programs
can be combined (the join of the projections is defined).
• Program Upgrade. Given a specification R and a candidate program P , and
given a new feature Q, we model the upgrade of P by Q as the problem
of producing a program that is correct with respect to Q and more-correct
than P with respect to R. We find that the upgrade can be obtained by
refining the join of Q with the projection of P on R; we also find that if the
join does not exist, then the upgrade is not possible without degrading the
relative correctness of P with respect to R.
32
Assertion Checking for verifying the relative correctness of a program with
respect to a previous version of the program. Lahiri et al. explore applications
of this technique as a tradeoff between soundness (which they concede) and
lower costs (which they hope to achieve). Also, they define relative correctness
between programs P and P ′ as the property that P ′ has a larger set of success-
ful traces and a smallest set of unsuccessful traces than P ; and they introduce
relative specifications as specifications that capture functionality of P ′ that P
does not have. By contrast, we use input/ output (or initil state/ final state)
relations as specifications, we represent program executions by functions from
initial states to final states, we characterize correct executions by initial state/
final state pairs that belong to the specification, and we make no distinction
between abort-freedom (a.k.a. safety, in Lahiri et al. (2013)) and normal func-
tional properties. Another important distinction with Lahiri et al. (2013) is
that we do not view relative correctness as a compromise that we accept as
a substitute for absolute correctness; rather we argue that in many cases, we
ought to test programs for relative correctness rather than absolute correct-
ness, regardless of cost. In other words, whereas Lahiri et al. argue in favor of
relative correctness on the grounds that it optimizes a quality vs. cost ratio,
we argue in favor on the grounds that it optimizes quality.
In Logozzo and Ball (2012), Logozzo and Ball introduce a definition of relative
correctness whereby a program P ′ is correct relative to P (an improvement
over P ) if and only if P ′ has more good traces and fewer bad traces than P .
Programs are modeled with trace semantics, and execution traces are com-
pared in terms of executable assertions inserted into P and P ′; in order for
the comparison to make sense, programs P and P ′ have to have the same
(or similar) structure and/or there must be a mapping from traces of P to
traces of P ′ . When P ′ is obtained from P by a transformation, and when P ′
is provably correct relative to P , the transformation in question is called a
verified repair. Like the work cited above (Logozzo et al. (2014); Lahiri et al.
(2013)), Logozzo and Ball model programs by execution traces and distinguish
between two types of failures: contract violations, when functional properties
are not satisfied; and run-time errors, when the execution causes an abort; for
the reasons we discuss above, we do not make this distinction, and model the
two aspects with the same relational framework.
References
Boudriga, N., Elloumi, F., Mili, A., 1992. The lattice of specifications: Ap-
plications to a specification methodology. Formal Aspects of Computing 4,
544–571.
Brink, C., Kahl, W., Schmidt, G., January 1997. Relational Methods in Com-
puter Science. Springer Verlag.
33
Desharnais, J., Diallo, N., Ghardallou, W., Frias, M., Jaoua, A., Mili, A.,
September 2015. Mathematics for relative correctness. In: Relational and
Algebraic Methods in Computer Science, 2015. Lisbon, Portugal.
Dijkstra, E., 1976. A Discipline of Programming. Prentice Hall.
Gries, D., 1981. The Science of programming. Springer Verlag.
Hehner, E., 1992. A Practical Theory of Programming. Prentice Hall.
Hoare, C., Oct. 1969. An axiomatic basis for computer programming. Com-
munications of the ACM 12 (10), 576 – 583.
Lahiri, S. K., McMillan, K. L., Sharma, R., Hawblitzel, C., 2013. Differential
assertion checking. In: Proceedings, ESEC/ SIGSOFT FSE. pp. 345–455.
Logozzo, F., Ball, T., 2012. Modular and verified automatic program repair.
In: Proceedings, OOPSLA. pp. 133–146.
Logozzo, F., Lahiri, S., Faehndrich, M., Blackshear, S., 2014. Verification mod-
ulo versions: Towards usable verification. In: Proceedings, PLDI. p. 32.
Manna, Z., 1974. A Mathematical Theory of Computation. McGraw Hill.
Mills, H., Basili, V., Gannon, J., Hamlet, D., 1986. Structured Programming:
A Mathematical Approach. Allyn and Bacon, Boston, Ma.
Schmidt, G., Stroehlein, T., 1990. Relationen und Graphen. Springer-Verlag,
Berlin, Germany.
34