Chapter 23 — Shorthands
The guarantee “the light is never on if nobody has pressed” is written with the keywords of chapters 21 and 22, but in the expanded form. The language provides short forms for frequent cases. This chapter describes these forms, called shorthands, and the rules on their meaning. It then describes how a name is given to an expression, to a function and to a derived event, and introduces named types, records and indexed states.
The shorthand
A shorthand is a short form that expands into an equivalent formula, written with the keywords of chapters 21 and 22 and called the expanded form. The meaning of a shorthand is only that of its expanded form: the English words that compose it serve as a reminder and do not define it.
Three rules follow:
- a line written with a shorthand has formal degree, like its expanded form;
- writing a shorthand or its expanded form does not change the contract;
- a program that evaluates formulas evaluates a shorthand through its expanded form.
bcdd recognises each shorthand as a form of its own, checks its names and types, and does not produce the
expanded form.
The guarantee in short form and in expanded form
The expanded form of the guarantee is:
GUARANTEE g9: ALWAYS (modo = accesa IMPLIES COUNT(premuto) > 0)
In every step in which the light is on there has been at least one press. The short form uses PRECEDES:
GUARANTEE g9: premuto PRECEDES modo = accesa
e PRECEDES q expands into ALWAYS (q IMPLIES COUNT(e) > 0): the expanded form of
premuto PRECEDES modo = accesa is the formula written above. The first element, e, is an event, because the
expanded form counts its steps.
The same guarantee can also be written with two other shorthands:
GUARANTEE g9: NEVER (modo = accesa AND COUNT(premuto) = 0)
GUARANTEE g9: BEFORE premuto: NEVER modo = accesa
NEVER p expands into ALWAYS NOT p. BEFORE e: P expands into WHILE COUNT(e) = 0: P, that is “in the steps
that precede the first e”. The three short forms therefore have three expanded forms, equivalent to one another:
| Short form | Expanded form |
|---|---|
premuto PRECEDES modo = accesa |
ALWAYS (modo = accesa IMPLIES COUNT(premuto) > 0) |
NEVER (modo = accesa AND COUNT(premuto) = 0) |
ALWAYS NOT (modo = accesa AND COUNT(premuto) = 0) |
BEFORE premuto: NEVER modo = accesa |
WHILE COUNT(premuto) = 0: ALWAYS NOT modo = accesa |
In the staircase light CSC g9 is written in short form, with PRECEDES, at line 39, after g8.
The response to a request, in short form
The detail g4a of chapter 22 also has a short form:
GUARANTEE g4a DETAILS g4: RESOLVES Pulizie WITHIN 1 s
RESOLVES X WITHIN d expands into WHENEVER requested(X) THEN accepted(X) OR rejected(X) WITHIN d, which is the
line written in chapter 22. The two lines are the same guarantee.
The shorthands of the language
The table shows the shorthands used in the guarantees of a CSC, with the expanded form of each.
| Short form | Expanded form | Reads |
|---|---|---|
NEVER p |
ALWAYS NOT p |
never p |
ONCE e |
COUNT(e) > 0 |
e has occurred at least once |
CHANGED(x) |
x <> PREV(x) |
the state x has changed value in this step |
e PRECEDES q |
ALWAYS (q IMPLIES COUNT(e) > 0) |
q does not hold before the first e |
BEFORE e: P |
WHILE COUNT(e) = 0: P |
P holds before the first e |
AFTER e: P |
WHILE COUNT(e) > 0: P |
P holds from the first e onwards, the step of e included |
ACCEPTS X ONLY WHILE c |
ALWAYS (accepted(X) IMPLIES c) |
the request X is accepted only if c holds |
X ENSURES p |
WHENEVER completed(X) THEN p AT ONCE |
when X succeeds, p holds |
RESOLVES X WITHIN d |
WHENEVER requested(X) THEN accepted(X) OR rejected(X) WITHIN d |
X has a response within d |
X REQUIRES c |
ALWAYS (requested(X) IMPLIES c) |
X may be requested only if c holds; written only in an assumption |
TRANSITION x: A -> B ON e WHEN c, … |
ALWAYS (CHANGED(x) IMPLIES ((PREV(x) = A AND x = B AND e AND c) OR …)) |
x changes value only in the listed ways |
ONCE and CHANGED are written inside a condition: ALWAYS (CHANGED(modo) IMPLIES ONCE premuto).
X REQUIRES c describes an obligation of the consumer and is written only in an assumption (ASSUME line).
A closed set of transitions: TRANSITION
TRANSITION lists all the ways in which a state changes value. Each entry A -> B ON e indicates that the state passes
from the value A to the value B in a step in which the event e occurs; with WHEN c the condition c must also
hold. The list is closed: a change that does not appear in it violates the guarantee. The type of the state is a list of
values; A and B are values of that list.
The mode of the light passes from accesa to spenta without an event of the boundary: the light switches off when the time runs out.
To name that step as an event a derived event is written, with DEFINE EVENT:
DEFINE EVENT scadenza := TIME SINCE premuto >= 85 s
scadenza occurs in the steps in which at least 85 seconds have elapsed since the last press. A derived event is
used in a formula in place of an event; it is not written in the steps of scenarios, which contain only events
declared with EVENT. Guarantee g10 lists the changes of the mode:
GUARANTEE g10: TRANSITION modo: spenta -> accesa ON premuto,
accesa -> spenta ON scadenza,
spenta -> in_pulizia ON accepted(Pulizie),
accesa -> in_pulizia ON accepted(Pulizie),
in_pulizia -> spenta ON completed(Pulizie),
in_pulizia -> spenta ON failed(Pulizie)
The lines, except the last, end with a comma and therefore continue on the next line (chapter 21): the guarantee is a single
declaration. A press during cleaning does not appear in the list, so it does not change the mode, as
g7 guarantees.
The header comment becomes:
-- VERSION 0.3: g1, g2 and g2a written as formulas; g3a, g4a, g4b, g7a, g8, g9 and g10 added. Pending approval.
In the report the two new lines are formal:
$ bcdd check UsoLuce.csc
bcdd check UsoLuce.csc
lines: 65 (recognised 55, comments 5, blank 5, unrecognised 0)
blocks: 1
line 4: CSC UsoLuce VERSION 0.3, STATUS HYPOTHESIS
1. ERRORS: 0
2. DEGREE OF THE CONTRACTUAL LINES
…
line 38: GUARANTEE g8 formal
line 39: GUARANTEE g9 formal
line 40: GUARANTEE g10 formal
…
Giving a name to an expression
The value of a named constant (chapter 8) can be an expression:
DEFINE DURATA_AVVISO := DURATA_LUCE - 5 s gives a name to a calculated duration. A DEFINE can also have
parameters, each with its type: it is then a function, which is used with the arguments written by name,
like the arguments of events in scenarios. With the following three new lines
DEFINE DURATA_LUCE := 90 s
DEFINE TOLLERANZA := 5 s
DEFINE vicino(t: Duration, valore: Duration) := ABS(t - valore) <= TOLLERANZA
the detail g2a is written:
GUARANTEE g2a DETAILS g2 STATUS HYPOTHESIS: ALWAYS ((PREV(modo) = accesa AND modo = spenta) IMPLIES (ONCE premuto AND vicino(t: TIME SINCE premuto, valore: DURATA_LUCE)))
vicino(t: …, valore: …) holds when the two durations differ by no more than TOLLERANZA. The line is formal:
1. ERRORS: 0
2. DEGREE OF THE CONTRACTUAL LINES
…
line 24: GUARANTEE g2a formal
…
bcdd checks that every argument is a parameter of the function and that none is missing, and checks its type.
For a call without valore bcdd reports error E24:
1. ERRORS: 1
line 24: [E24] the argument valore is missing in the call to vicino
DEFINEs must not refer to one another circularly: for DEFINE A := B + 1 with DEFINE B := A - 1 bcdd
reports error E28. A DEFINE that details another DEFINE (DEFINE nome DETAILS padre := …) is pending approval like every detail, and is approved with
bcdd ratify like a contractual line.
Named types, records and indexed states
In a three-storey building the staircase light has a button and a lamp per floor. The CSC LucePiani uses three
new forms:
-- The staircase light of a three-storey building: one button and one lamp per floor.
CSC LucePiani VERSION 0.1
STATUS HYPOTHESIS
PURPOSE "The person on the stairs presses the button on their own floor and has light on that floor"
TYPE Piano := {terra, primo, secondo}
TYPE Percentuale := Integer [0 .. 100]
TYPE Tocco := Record {piano: Piano, lungo: Boolean}
EVENT IN premuto(dove: Piano)
EVENT IN toccato(t: Tocco)
STATE accesa[Piano] : Boolean INITIAL false
STATE ultimo : Piano INITIAL terra FOLLOWS premuto.dove
STATE intensita : Percentuale INITIAL 0
GUARANTEE p1: FOR ALL p IN Piano: WHENEVER (premuto WITH dove = p) THEN accesa[p] AT ONCE
GUARANTEE p2: ALWAYS (toccato IMPLIES accesa[LAST(toccato).t.piano])
GUARANTEE p3: ALWAYS (intensita > 0 IMPLIES accesa[ultimo])
SCENARIO q1 EXPECT ADMITTED
@0 s premuto(dove: primo) accesa[primo] = true
@1 s toccato(t: _)
END
- a named type:
TYPE Percentuale := Integer [0 .. 100]gives a name to a type; the name stands for the type it names, throughout the block. A limit of the interval can be omitted:Integer [0 ..]is a non-negative integer without maximum; - a record:
TYPE Tocco := Record {piano: Piano, lungo: Boolean}is a type with fields;x.camponames one of its fields, andLAST(e).pthe value of the parameterpin the last step in whicheoccurred. In a scenario the value of a parameter of record type is written_; - an indexed state:
STATE accesa[Piano] : Boolean INITIAL falseis equivalent to one state per floor:accesa[terra],accesa[primo],accesa[secondo]. The type of the index is finite: a list of values,Boolean, or a named type defined as one of these or as anIntegerwith both limits.
FOR ALL p IN Piano: P holds for every value of the type, with p taking each value in turn: guarantee p1 is
the same guarantee written three times, once per floor. STATE ultimo : Piano INITIAL terra FOLLOWS premuto.dove
declares a state that follows the parameter dove of the last premuto. Its expanded form is the pair of formulas
ALWAYS (premuto IMPLIES ultimo = LAST(premuto).dove) and ALWAYS (CHANGED(ultimo) IMPLIES premuto). FOR ALL, indexes and FOLLOWS are
shorthands.
The report has no errors:
1. ERRORS: 0
2. DEGREE OF THE CONTRACTUAL LINES
verbal: 0
formal: 3
declared extension: 0
unrecognised: 0
line 17: GUARANTEE p1 formal
line 18: GUARANTEE p2 formal
line 19: GUARANTEE p3 formal
bcdd checks the fields, the indexes and the literal values. Four defects are introduced: a guarantee names a
field stanza that the record does not have, ALWAYS accesa is written without an index, a step presses the
button at floor quarto, and the same step brings the intensity to 120. The report shows four errors:
1. ERRORS: 4
line 20: [E24] name not declared as a field of Tocco: stanza
line 21: [E29] accesa has an index: write accesa[value of Piano]
line 26: [E03] name not declared as a value of TYPE: quarto
line 26: [E25] value not of type Percentuale: 120
The value 120 is outside the interval of the type Percentuale: bcdd compares the literal
values of the INITIAL clause, of the GIVEN clause, of assignments and of the arguments of steps with the
declared type (error E25).
Summary
- A shorthand is a short form that expands into an equivalent formula, the expanded form; its meaning is only that of the expanded form.
- A line written with a shorthand has formal degree.
- Several shorthands can express the same guarantee:
PRECEDES,NEVERandBEFOREin the example ofg9. RESOLVESexpresses in short form the response to a request within a time;TRANSITIONlists the closed set of transitions of a state.DEFINEgives a name to an expression, to a function with parameters, or, withDEFINE EVENT, to a derived event.TYPE Name := Typegives a name to a type;Record {…}is a type with fields;STATE x[T]is a state indexed on a finite type;FOR ALLandFOLLOWSare shorthands.
Special cases
Short forms with an incomplete expanded form. The language also provides the forms AFTER e UNTIL f: P,
BETWEEN e AND f: P and p FOR AT LEAST d. The first two delimit an interval between two events; the third requires
that a condition hold for a minimum duration. The expanded form of AFTER e UNTIL f: P is a WHILE scope on a
DEFINE. The DEFINE holds from an e to the first following f and is computed with PREV on the steps of the
trace that have already elapsed. For BETWEEN and FOR AT LEAST the expanded form is not yet fully defined. bcdd recognises the three
forms and checks their names and types; the manual does not
use them.
REQUIRES in a guarantee. X REQUIRES c describes what the consumer must satisfy before making the request.
If the form is written in a guarantee (GUARANTEE line), bcdd reports error E27, and the message indicates
the form to write:
1. ERRORS: 1
line 39: [E27] REQUIRES is used only in an ASSUME: in a GUARANTEE write ALWAYS (requested(X) IMPLIES c)
Variants. VARIANT (chapter 20), too, reduces to other forms: an entity with variants is equivalent to the
set of its compositions, each written as an entity without variants. VARIANT does not expand into a formula, so it is not a shorthand in the sense of this
chapter.
The short form in the text in words. In VERBAL "the light never switches on BEFORE a press" the
words in quotation marks are text, not a shorthand: the line remains verbal.
2. DEGREE OF THE CONTRACTUAL LINES
…
line 39: GUARANTEE g9 verbal
…

