– 07 – 2015-05-21 – main –
Softwaretechnik / Software-Engineering
Lecture 07: Formal Methods for Requirements Engineering
2015-05-21
- Prof. Dr. Andreas Podelski, Dr. Bernd Westphal
Albert-Ludwigs-Universit¨ at Freiburg, Germany
Lecture 07: Formal Methods for Requirements Engineering 2015-05-21 - - PowerPoint PPT Presentation
Softwaretechnik / Software-Engineering Lecture 07: Formal Methods for Requirements Engineering 2015-05-21 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal 07 2015-05-21 main Albert-Ludwigs-Universit at Freiburg, Germany 07
– 07 – 2015-05-21 – main –
Albert-Ludwigs-Universit¨ at Freiburg, Germany
– 07 – 2015-05-21 – main –
2/54
– 07 – 2015-05-21 – main –
3/54 L 1: 20.4., Mo
Introduction
T 1: 23.4., Do L 2: 27.4., Mo L 3: 30.4., Do L 4: 4.5., Mo
Development Process, Metrics
T 2: 7.5., Do L 5: 11.5., Mo
L 6: 18.5., Mo L 7: 21.5., Do
Requirements Engineering
T 3: 1.6., Mo
L 8: 8.6., Mo L 9: 11.6., Do L 10: 15.6., Mo
Design Modelling & Analysis
T 4: 18.6., Do L 11: 22.6., Mo L 12: 25.6., Do L 13: 29.6., Mo
Implementation, Testing
T 5: 2.7., Do L 14: 6.7., Mo L 15: 9.7., Do L 16: 13.7., Mo
Formal Verification
T 6: 16.7., Do L 17: 20.7., Mo
The Rest
L 18: 23.7., Do
– 07 – 2015-05-21 – Sprelim –
4/54
Last Lecture:
This Lecture:
– 07 – 2015-05-21 – Srefm –
5/54
Formal Methods (in the Software Development Domain)
– 1 – 2015-04-20 – main –
20/37
... back to “ ‘technological paradise’ where ‘no acts of God can be permitted’ and everything happens according to the blueprints”.
(Kopetz, 2011; Lovins and Lovins, 2001)
A method is called formal method if and only if its techniques and tools can be explained in mathematics. Example: If a method includes, as a tool, a specification language, then that language has
Formal, Rigorous, or Systematic Development
– 1 – 2015-04-20 – main –
21/37
“The techniques of a formal method help
The techniques of a formal method, (besides the specification languages) are typically software packages that help developers use the techniques and other tools. The aim of developing software, either
is to (be able to) reason in a precise manner about properties of what is being developed.” (Bjørner and Havelund, 2014)
Decision tables (DT) are one example for a formal requirements specification language:
completeness, can be formally defined,
whether it is complete or not,
automatically (→ tool support).
– 07 – 2015-05-21 – Srefm –
6/54
... so, off to “ ‘technological paradise’ where [...] everything happens according to the blueprints”.
(Kopetz, 2011; Lovins and Lovins, 2001)
– 07 – 2015-05-21 – main –
7/54
– 07 – 2015-05-21 – Set –
8/54
a set of actions. (i) The set Φ(C) of premises over C consists of the terms defined by the following grammar: ϕ ::= true | c | ¬ϕ1 | ϕ1 ∨ ϕ2, c ∈ C. (ii) A rule r (over C and A) is a pair (ϕ, α), written ϕ → α, which comprises
(iii) Any finite set T of rules (over C and A) is called decision table (over C and A).
– 07 – 2015-05-21 – Set –
9/54
This might’ve been the specification of lecture hall 101-0-026’s ventilation system:
C = {button pressed, ventilation on, ventilation off } shorthands: {b, on, off }.
A = {do ventilate, stop ventilate} shorthands: {go, stop}.
T = {r1, r2}.
– 07 – 2015-05-21 – Set –
10/54
T: room ventilation r1 r2 b button pressed? × ×
ventilation off? ×
ventilation on?
go start ventilation ×
stop ventilation
From the table to the rules:
– 07 – 2015-05-21 – Set –
10/54
T: room ventilation r1 r2 b button pressed? × ×
ventilation off? ×
ventilation on?
go start ventilation ×
stop ventilation
r3 ∗
– 07 – 2015-05-21 – Set –
11/54
T: decision table r1 · · · rn c1 description condition 1 v1,1 · · · v1,n . . . . . . . . . ... . . . cm description condition m vm,1 · · · vm,n a1 description action 1 w1,1 · · · w1,n . . . . . . . . . ... . . . ak description action k wk,1 · · · wk,n vi,j ∈ {−, ×, ∗}, wi,j ∈ {−, ×}
c , if v = × ¬c , if v = − true , if v = ∗
Recall:
1≤j≤m F(vj,i, ci) = true by definition.
(multiple tables T1, . . . , Tn denote one set of rules)
– 07 – 2015-05-21 – Set –
12/54 T1: cash a cheque r1 r2 else c1 credit limit exceeded? × × c2 payment history ok? ×
a1 cash cheque ×
a2 do not cash cheque
×
σ
{a1,a3}
− − − − − → σ′ if σ = {c1 → 1, c2 → 1, c3 → 0}.
– 07 – 2015-05-21 – Set –
13/54
= true, for all σ ∈ Σ,
= c, if and only if σ(c) = 1,
= ¬ϕ1, if and only if σ | = ϕ,
= ϕ1 ∨ ϕ2, if and only if σ | = ϕ1 or σ | = ϕ2.
Note: In the following, we may use ∧, = ⇒ , ⇐ ⇒ as abbreviations as usual.
= ϕ.
interleaving semantics/interpretation of T, consists of the finite or infinite computation paths π = σ0
α1
− → σ1
α2
− → σ2 · · · , σi ∈ Σ, i ∈ N0, where ∀ i ∈ N0 ∃ r = ϕ → α ∈ T • σi | = ϕ ∧ αi+1 = α.
– 07 – 2015-05-21 – Set –
14/54 Back to lecture hall 101-0-026’s ventilation system:
shorthands: {b, on, off }.
shorthands: {go, stop}.
r2 = b ∧ ventilation on → {stop}, T = {r1, r2}. What’s in Tinterleaving? Naja, for example
{go}
− − − → σ1
{stop}
− − − − → σ2
σ0 = {b → 1, off → 1, on → 0}, σ1 = {b → 1, off → 0, on → 1}
σ0 = {b → 0, off → 1, on → 0}
{go}
− − − → σ1
{go}
− − − → σ2
σ0 = {b → 1, off → 1, on → 0}, σ1 = {b → 1, off → 1, on → 0}
{go}
− − − → σ1
{go}
− − − → σ2 . . .
σi = {b → 1, off → 1, on → 0}, i ∈ N0
{go}
− − − → σ1
{go,stop}
− − − − − − → σ2
σ0 = {b → 0, off → 1, on → 0},
– 07 – 2015-05-21 – Set –
15/54
set S of (finite or infinite) computation paths of the form σ0
α1
− → σ1
α2
− → σ2 · · · where
The (possibly partial) function · : S → S is called interpreta- tion of S.
(surprise, surprise!?)
– 07 – 2015-05-21 – Set –
16/54
– 07 – 2015-05-21 – Set –
16/54
αs
1
− → σs
1 αs
2
− → σs
2 · · · , . . . }, σs i ∈ Σs.
M : As → 2A a mapping of events to sets of actions.
∀ σs
αs
1
− → σs
1 αs
2
− → σs
2 · · · ∈ S • I(σs 0) M(α1)
− − − − → I(σs
1) · · · ∈ Tinterleaving
Tspec := {S | ∃ I, M • S implements T wrt. I and M}.
behaviour, satisfies the specification T.
what is not a computation path of T is forbidden for the final product.
A software S′ which is a refinement of a software S ∈ Tspec satisfies specification T.
– 07 – 2015-05-21 – Set –
17/54
How can these I and M look like? Example:
I : σ1 → σ1, the identity
0 ; σ2(b) ∈ B (button state), σ2(V ) ∈ R+ 0 (voltage at ventilator)
I is defined by:
I(σ3)(b) = 1 if and only if value of b in σ is Java’s true.
from σs ∈ Σs whether the conditions (here: b, on, off ) should be considered 0 or 1 in σ.
– 07 – 2015-05-21 – main –
18/54
– 07 – 2015-05-21 – Setprop –
19/54
– 05 – 2015-05-11 – Sre –
22/90
A requirements specification should be
— it correctly represents the wishes/needs of the customer,
— all requirements (existing in somebody’s head, or a document, or . . . ) should be present,
— things which are not relevant to the project should not be constrained,
— each requirement is compatible with all other requirements; otherwise the requirements are not realisable,
— a requirements specification does not constrain the realisation more than necessary,
— the sources of requirements are documented, requirements are uniquely identifiable,
— the final product can objectively be checked for satisfying a requirement.
– 07 – 2015-05-21 – Setprop –
20/54
the customer” → still difficult;
“did we cover all cases?”;
decision tables;
realisation → still difficult;
But formal requirements specification language tend to support abstract specifications; specifying technical details is tedious.
meta-properties, need to be established separately;
using decision tables, is immediately
We can formally define additional quality criteria:
desired,
model,
– 07 – 2015-05-21 – Setprop –
21/54
is no state σ ∈ Σ such that σ | = ϕ.
is another (different) rule r′ whose premise ϕ′ is subsumed by ϕ and whose effect is the same as r’s, i.e. if ∃ r′ = ϕ′ → α′, r′ = r • | = ϕ = ⇒ ϕ′ ∧ α = α′. r′ is called subsumed by r.
– 07 – 2015-05-21 – Setprop –
22/54
Example:
Proposition: any rule with insatisfiable premise is vacuous.
r1 r2 r3 r4 b button pressed? × ×
ventilation off? ×
ventilation on?
∗
start ventilation ×
stop ventilation
be subsumed by another rule).
– 07 – 2015-05-21 – Setprop –
23/54
The decision table T with useless rules has the same computation paths as the one with useless rules removed, thus specifies the same set of software.
(read, maintain, . . . ).
– 07 – 2015-05-21 – Setprop –
24/54
| =
ϕ.
– 07 – 2015-05-21 – Setprop –
25/54 T: room ventilation r1 r2 b button pressed? × ×
ventilation off? ×
ventilation on?
go start ventilation ×
stop ventilation
– 07 – 2015-05-21 – Setprop –
25/54 T: room ventilation r1 r2 b button pressed? × ×
ventilation off? ×
ventilation on?
go start ventilation ×
stop ventilation
T: room ventilation r1 r2 r3 r4 r5 b button pressed? × ×
∗
ventilation off? ×
×
ventilation on?
∗ ×
start ventilation ×
stop ventilation
– 07 – 2015-05-21 – Setprop –
25/54 T: room ventilation r1 r2 b button pressed? × ×
ventilation off? ×
ventilation on?
go start ventilation ×
stop ventilation
T: room ventilation r1 r2 else b button pressed? × ×
ventilation off? ×
ventilation on?
go start ventilation ×
stop ventilation
– 07 – 2015-05-21 – Setprop –
26/54
T: room ventilation r1 b button pressed? ×
ventilation off? ×
ventilation on?
start ventilation × stop stop ventilation
– 07 – 2015-05-21 – Setprop –
27/54
Definition.
[Determinism] A decision table T is called deterministic if
and only if the premises of all rules are pairwise disjoint, i.e. if ∀ (ϕi → αi), (ϕj → αj) ∈ T, i = j• | = ¬(ϕi ∧ ϕj). Otherwise, T is called non-deterministic.
– 07 – 2015-05-21 – Setprop –
28/54 T: room ventilation r1 r2 r3 b button pressed? × ×
start ventilation ×
stop ventilation
= b, rules r1 and r2 are both enabled.
under certain conditions (which I will specify later), and
under certain conditions (which I will specify later).
condition) want to see on and off executed together.
– 07 – 2015-05-21 – Setprop –
29/54
(more freedom) to the developer.
even the choice to create a non-deterministic final product. (Input-)Deterministic final products, i.e. “same data in, same data out”, are easier to deal with and are usually desired.
deterministic decision tables can be implemented with deterministic programming languages. For deterministic decision tables, we can easily devise code generation patterns.
– 07 – 2015-05-21 – Setprop –
30/54
T: room ventilation r1 r2 else b button pressed? × ×
ventilation off? ×
ventilation on?
go start ventilation ×
stop ventilation
i nt b ,
2 3
extern void go ( ) ; extern void stop ( ) ;
4 5
void (∗ e f f e c t ) ( ) = 0;
6 7
void dt () {
8 9
r e a d b o n o f f ( ) ; // read
10 11
// compute
12
//
13
i f (b && o f f ) e f f e c t = go ;
14 15
i f (b && on ) e f f e c t = stop ;
16 17
e x e c u t e e f f e c t ( ) ; // w r i t e
18
}
– 07 – 2015-05-21 – main –
31/54
– 07 – 2015-05-21 – Setconflax –
32/54
T: room ventilation r1 r2 else b button pressed? × ×
ventilation off? ×
ventilation on?
go start ventilation ×
stop ventilation
software systems, which are used in the real world.
relations between actions/conditions in the real-world (→ domain model (Bjørner, 2006)).
Example:
= on ∧ off never happens in reality,
= on ∧ off is still possible. T “doesn’t know” that on and off are opposites in the real-world; maybe it should.
then σ | = on ∧ off is possible in reality (e.g. due to sensor failures).
– 07 – 2015-05-21 – Setconflax –
33/54
T: room ventilation r1 r2 r else b button pressed? × × ∗
ventilation off? ×
ventilation on?
× go start ventilation ×
stop ventilation
cannot happen ×
– 07 – 2015-05-21 – Setconflax –
34/54
i.e. all those combinations of condition values, which ‘cannot happen’ according to our understanding of the domain. Standard semantics wrt. conflict axiom:
interleaving semantics/interpretation of T under conflict axiom ϕconfl, consists of the finite or infinite computation paths π = σ0
α1
− − → σ1
α2
− − → σ2 · · · , σi ∈ {σ ∈ Σ | σ | = ϕconfl}, i ∈ N0, where ∀ i ∈ N0 ∃ r = ϕ → α ∈ T • σi | = ϕ ∧ αi+1 = α.
– 07 – 2015-05-21 – Setconflax –
35/54
is called vacuous wrt. conflict axiom ϕconfl ∈ Φ(C) if and only if the premise
= (ϕ = ⇒ ϕconfl).
complete wrt. conflict axiom ϕconfl if and only if the disjunction of the conflict axiom and all rules’ premises is a tautology, i.e. if | = ϕconfl ∨
ϕ.
Fits intuition: ϕconfl = false means we don’t exclude any states from consideration.
– 07 – 2015-05-21 – Setconflax –
36/54
“on models an opposite of off , neither can both be satisfied nor bot non-satisfied”
T: room ventilation r1 r2 r3 b button pressed? × ×
ventilation off? ×
ventilation on?
∗ go start ventilation ×
stop ventilation
is complete wrt. ϕconfl.
– 07 – 2015-05-21 – Setconflax –
37/54
Same as with uselessness and general vacuity, doesn’t hurt but May make communication with customer harder! Implementing vacuous rules is a waste of effort!
An incomplete decision table may allow too little behaviour (it forbids too much)! May not be the intention of the customer!
– 07 – 2015-05-21 – Setconflax –
38/54
“Airbus A320-200 overran runway at Okecie Intl. Airport on 14 Sep. 1993.”
(i) at least 6.3 tons weight on each main landing gear strut, (ii) the wheels of the plane must be turning faster than 133 km/h.
14 Sep. 1993:
ced crosswind,
puts too little weight on landing gear
to hydroplaning.
”Lufthansa Flight 2904 crash site Siecinski” by Mariusz Siecinski - http://www.airliners.net/photo/Lufthansa/Airbus-A320-211/0265541/L/. Licensed under GFDL via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Lufthansa Flight 2904 crash site Siecinski.jpg ”Flight 29041129” by Anynobody - Own work. Licensed under CC BY-SA 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Flight 29041129.png#/media/File:Flight 29041129.png
– 07 – 2015-05-21 – main –
39/54
– 07 – 2015-05-21 – Setconflrel –
40/54
actions.
(i) r is called consistent with conflict relation if and only if there are no conflicting actions in α, i.e. if ∄ a1, a2 ∈ α • a1a2. (ii) T is called consistent with iff all rules r ∈ T are consistent with .
– 07 – 2015-05-21 – Setconflrel –
41/54
“actions stop and go are not supposed to be executed at the same time” T: room ventilation r1 b button pressed? ×
ventilation off?
ventilation on? × go start ventilation × stop stop ventilation ×
– 07 – 2015-05-21 – Setconflrel –
42/54
A decision table with inconsistent rules may do harm in operation! Detecting an inconsistency only late during a project can incur significant cost! Inconsistencies (in particular in (multiple) decision tables, created and edited by multiple people, as well as in requirements in general) are not always as obvious as in the toy examples given here! (would be too easy...) And is more difficult to handle with the collecting semantics.
– 07 – 2015-05-21 – main –
43/54
– 07 – 2015-05-21 – Setcoll –
44/54
α1
− − → σ1
α2
− − → σ2 · · · a state/event sequence.
∀ i ∈ N0 ∃ r = ϕ → α ∈ T • σi | = ϕ ∧ αi+1 = α.
∀ i ∈ N0 ∃ r = ϕ → α ∈ T • σi | = ϕ ∧ αi+1 =
σi| =ϕ′
α′. That is, all rules which are enabled in σi “fire” simultaneously, the joint effect is the union of the effects.
– 07 – 2015-05-21 – Setcoll –
45/54
– 07 – 2015-05-21 – Setcoll –
46/54
Actions are uninterpreted.
Here it makes sense, because the next state seen by the bank clerk may be the result of many database updates by other bank clerks, not only hers/his. We can also define a semantics with action effects:
a new state σ′. σ′ is called the result of applying a to σ.
goacteff (σ) = {b → σ(b), on → 1, off → 0} stopacteff (σ) = {b → σ(b), on → 0, off → 1}
∀ i ∈ N0 ∃ r = ϕ → α ∈ T • σi | = ϕ ∧ αi+1 = α ∧ σi+1 = αacteff (σ).
– 07 – 2015-05-21 – Setcoll –
47/54
T: room ventilation r1
ventilation off? ×
ventilation on?
start ventilation × stop stop ventilation
σ0
− − → σ1 with σ1 = {on → 0, off → 1}.
enabled, because no state satisfying the premise is ever reached (even with conflict axiom ϕconfl = false).
– 07 – 2015-05-21 – Setcoll –
48/54
C = Cc ˙ ∪ Cu.
user external to the computer system)
We want the specification to be able to deal with all possible sequences of inputs, i.e. we require T|Cu = (Σ|Cu)ω ( or (Σ|Cu)∗).
– 07 – 2015-05-21 – Setcoll –
49/54
T: room ventilation r1 r2 b button pressed? ×
ventilation off? ×
ventilation on?
go start ventilation ×
stop ventilation
There is no rule enabled if the button is pressed when the ventilation is off.
system stops to work; it “gets stuck” in that state. (Because in order to take a transition, we need to have at least one enabled rule.)
– 07 – 2015-05-21 – main –
50/54
– 07 – 2015-05-21 – Setdisc –
51/54
specification language with
reason about properties of what is being developed. We can, e.g., prove that a decision table is complete. (Automatically?)
course) depends on the project.
they don’t scale so well in the number of conditions.
– 07 – 2015-05-21 – Setdisc –
52/54 “Es ist aussichtslos, den Klienten mit formalen Darstellungen zu kommen; [...]”
(“It is futile to approach clients with formal representations”) (Ludewig and Lichter, 2013)
ϕ → α
T: room ventilation r1 r2 else b button pressed? × ×Customer Developer
here, just check and update if needed
WAT?!
– 07 – 2015-05-21 – Setdisc –
52/54 “Es ist aussichtslos, den Klienten mit formalen Darstellungen zu kommen; [...]”
(“It is futile to approach clients with formal representations”) (Ludewig and Lichter, 2013)
ϕ → α
T: room ventilation r1 r2 else b button pressed? × ×Customer Developer
here, just check and update if needed
WAT?!
– 07 – 2015-05-21 – main –
53/54
– 07 – 2015-05-21 – main –
54/54 Balzert, H. (2009). Lehrbuch der Softwaretechnik: Basiskonzepte und Requirements
Bjørner, D. (2006). Software Engineering, Vol. 3: Domains, Requirements and Software Design. Springer-Verlag. Kopetz, H. (2011). What I learned from Brian. In Jones, C. B. et al., editors, Dependable and Historic Computing, volume 6875 of LNCS. Springer. Lovins, A. B. and Lovins, L. H. (2001). Brittle Power - Energy Strategy for National Security. Rocky Mountain Institute. Ludewig, J. and Lichter, H. (2013). Software Engineering. dpunkt.verlag, 3. edition. Wikipedia (2015). Lufthansa flight 2904. id 646105486, Feb., 7th, 2015.