Introduction to Alloy

Topic 4: Advanced topics

13 April 2013

In which we prepare to wrap up.

1 Recursion

How can we do without recursion?

1.1 An example

2 Sequences

  • ways to define sequences
  • the util/ordering library
  • built-in functions for orderings

2.1 Ways to define sequences (and SLOs)

  • Define a next relation on the items (i.e. DIY).
  • Various utility libraries (util/sequence, util/seqrel, ...)
  • util/ordering
  • (in Alloy 4.2) the seq keyword

2.2 The util/ordering library

Provides a variety of helpful functions and predicates:
  • first, last, prev[Item], next[Item]
  • larger [x, y], smaller [x, y] (one Item), max [es: set Item], min [es: set Item] (lone Item), prevs[Item], nexts[Item] (set Item)
  • lt [e1, e2: Item], gt [e1, e2: Item], lte [e1, e2: Item], gte [e1, e2: Item]

2.3 The seq keyword

3 Dynamic systems

Ways to model state change in Alloy:
  • operations
  • traces
  • explicit time
  • events

3.1 Defining operations

Consider a model of manuscript transmission:
sig MS {
  exemplar : lone MS
}
sig State {
  extant : set MS,
  lost : set MS - extant
}

3.2 Defining operations (2)

Define how state can change:
pred step [disj s, s' : State] {
  s' = next[s]
  some destroyed, new_copies : set MS |
    destroyed in s.extant
    and new_copies in MS - (s.extant + s.lost)
    and (all c : new_copies | 
             some c.exemplar 
             and c.exemplar in s.extant)
    and s'.extant = new_copies + s.extant - destroyed
    and s'.lost = s.lost + destroyed
}

3.3 Traces (1)

Import the util/ordering library:
open util/ordering[State]

3.4 Traces (2)

Define initial state:
pred initial_state [ s : State ] {
  one s.extant
  no s.extant.exemplar
  no s.lost
}

3.5 Traces (3)

Define state sequence:
pred history {
  initial_state[first]
  all s : State - last | 
    let s' = next[s] | 
      step[s, s']
}

3.6 Events

An event-oriented idiom is also available; allows quantifying over events.

4 Describing individual instances

Two ways to explore individual instances in Alloy:
  • define a universe
  • define a predicate
(Examples.)

5 Q/A

Questions and discussion

6 Where do we go from here?

Resources: