Example Solution
Example Solution
Please read these directions but wait for the signal to begin working
• You have 75 minutes to complete the test. Do not spend too much time on any
of the problems.
• If you find any ambiguities in a question, resolve them to the best of your
understanding and specify how you did it.
• Answer each question in the space provided. You should not need more space.
You can use the back of pages for scratch work.
• This booklet should have 8 pages including this one. Contact the exam proctor
immediately if it does not.
1. (9 points) True/False questions
Circle T or F depending on whether you think the statement is true or false.
T F Testing can only show the presence of errors, not their absence. (T)
T F Formal methods apply only at the early stages of software development. (F)
T F One advantage of formal verification is that it can be always fully automated. (F)
T F Alloy was designed for modeling software design and code. (F)
T F The transpose operation in Alloy is idempotent, that is, ~(~r) = r for all relations r.
(T)
T F When the Alloy Analyzer fails to find an instance of a model it is always because the
constraints expressed by model are jointly unsatisfiable. (T)
T F When the Alloy Analyzer fails to disprove an assertion for a model then that assertion
holds in the model. (F)
T F In computational systems, invariant (or safety) properties are properties that we expect
to hold at all times. (T)
T F Writing and checking expected properties of a Lustre model helps us check the correct-
ness of the modeled system with respect to its intended behavior. (T)
Page 2
2. (9 points) Consider the following Alloy signature
2. The set of all people that have only girls (i.e., whose children, if any, are all female).
{ p: Person | p.children in Woman }
3. The set of all people that have exactly a boy and a girl.
{ p: Person | some c1: Man | some c2: Woman | p.children = c1 + c2 }
3. (3 points) Express as an Alloy formula the fact that three sets B1, B2, B3 are a partition of a
set A. Do not assume that these sets are signatures.
{
a = b1 + b2 + b3
no (b1 & b2)
no (b1 & b3)
no (b2 & b3)
}
Page 3
6. (6 points) Each of the following Alloy constraints on a relation r of type A -> A (for some
signature A) expresses a property of binary relations.
Connect with a line each constraint to the corresponding property among those listed on the
right.
some r (1) (a) irreflexive (no element is related to itself)
r.r in r (2) (b) injective (no two elements are related to the same element)
no (iden & r) (3) (c) nonempty
~r in r (4) (d) transitive (if a is related to b and b to c then a is related to c)
~r.r in iden (5) (e) functional (every element is related to at most one element)
r.~r in iden (6) (f) symmetric (a is related to b only if b is related to a)
Recall that iden is the identity relation which holds only for pairs of the form (a, a) where a
is member of A.
1 7→ c, 2 7→ d, 3 7→ a, 4 7→ f , 5 7→ e, 6 7→ b
7. (10 points) Suppose you are modeling each of the following relations as a binary relation.
Which of the properties listed in the previous problem would you expect each relation to have?
(Write just the letter of a property.)
1. the relation sibling between people with the same biological parents;
a, f
2. the relation mother between a person and that person’s biological mother;
a, e
3. the relation contains between directories in a file system and their contents;
a, d
Page 4
8. (8 points) Consider the following Alloy model:
For each of the instances below say whether it satisfies the model or not. If it does not, also
briefly explain why.
Page 5
9. (9 points) Consider the following highly simplified Alloy model of a public library with several
book titles and one or more copy per title. At any one time, a book copy is available in the
library if it is not currently checked out by a library patron.
Borrow: A patron borrows an available copy c of a book (title) b. The only effect of this
operation is that the checked out copy c becomes unavailable.
Return: A book copy c is returned to the library. The only effect of this operation is that the
returned copy becomes available again.
Provide below a definition of the Alloy predicates borrow and return, modeling the two opera-
tors described above. Then provide a definition of the trans predicate, modeling the transition
relation for a transition system corresponding to these two operators only.
Page 6
10. (3 points) Define in Lustre the temporal operator UntilNow which takes a Boolean input X
and returns true iff X is currently true and has been continuously true from the start.
11. (3 points) Define in Lustre the temporal operator HasOccurred which takes a Boolean input
X and returns true if and only if X was ever true—possibly including now.
12. (3 points) Define a Lustre node that takes as input an integer N and a Boolean Reset and
returns an integer value C satisfying the following requirements.
C starts at zero and increases by one at each step as long as it is stays (strictly) smaller than
the initial value of N and Reset is currently false. In all other cases, it goes back to zero.
Write your definition under the assumption that the initial value of N is positive (that is, do
not consider that possibility that initially N ≤ 0).
Page 7
14. (14 points) Write in Lustre the following properties of Counter from the previous problem,
which we expect to hold when the initial value of N is positive.
You may use as needed the operators HasOccurred, UntilNow, IsConstant, and First where
First is the unary operator seen in class that always returns the initial value of its input
stream.
(Note that you can do this problem even if you did not complete those in the previous page.)
-- C ranges between 0, included, and the initial value of N, excluded
P3 = true -> (not Reset and pre C <> N0 - 1) => pre C < C;
Note: P3, P4 are set to true initially because the property is really about later execution steps.
Page 8