The document discusses modeling state for computational systems. It describes defining state using variables of different types, and iteratively defining the state, invariants, initial state, actions, and display. An example of modeling the state of a clock is provided, showing initial attempts, mistakes, and refinements to properly define the clock's state and possible actions. Key aspects of defining state are also outlined, such as having too little or too much state defined, and ensuring internal consistency between the state, scenarios, actions, and invariants.
2. what is state
that in the present
of that in the past
which affects that of the future
time
3. modelling state
describe state using variables
– a bit like programming
types of variables:
– basic type:
x: Nat – non-negative integer {0,1,2,...}
– individual item from set:
shape: {circle, line, rectangle}
– subset of bigger set:
selection: set Nat – set of integers
– function (often finite):
objects: Nat shape
– user defined:
Point = x, y: Real – e.g. (1.79,-3.2)
also:
Int – pos or neg integer
Real – fractional number
String, etc.
4. stages
iteratively define:
state – what needs to be remembered
invariants – what is always true
initial state – how it starts
actions – what can happen to the state
(need to relate these to mouse, keys, etc.)
display – what the user sees (hears etc.)
use scenarios to check they are what you want
5. example: car clock
three buttons:
mode – cycles between hours, mins, seconds
+/– – increments/decrements selected item
we will define state and actions
N.B. will not be right first time ... spot the mistakes ...
16:55:00
mode – +
6. clock state – first attempt
state
hours: Nat
mins: Nat – all just numbers
secs: Nat
hours < 24 ∧ mins < 60 ∧ secs < 60
initial state
hours = 0
mins = 0
secs= 0
display
hours “:” mins “:” secs
invariant
7. clock actions – first attempt
increment (+)
add 1 to selected item
others unchanged
decrement (–)
similar
mode
cycle selected item
what is it?
8. clock state – second attempt
state
hours: Nat, mins: Nat, secs: Nat – all just numbers
selected: { ‘NONE’, ‘HRS’, ‘MINS’, ‘SECS’ }
hours < 24 ∧ mins < 60 ∧ secs < 60
initial state
hours = 0, mins = 0, secs= 0
selected = ‘NONE’
display
hours “:” mins “:” secs (with selected flashing)
9. clock actions – second attempt
increment (+)
if ( selected = ‘NONE’ ) do nothing
if ( selected = ‘HRS’ ) hours’ = hours+1
...
decrement (–)
similar
mode
if ( selected = ‘NONE’ ) selected’ = ‘HRS’
...
variable with apostrophe
(called ‘prime’)
is state after action
10. clock– scenario
time is 22:58:33
user types: mode mode + +
action selected hours mins secs
NONE 22 58 33
mode
HRS 22 58 33
mode
MINS 22 58 33
increment (+)
MINS 22 59 33
increment (+)
MINS 22 60 33
!!!
11. clock actions – third attempt
increment (+)
if ( selected = ‘NONE’ ) do nothing
if ( selected = ‘HRS’ )
if ( hours < 23 ) hours’ = hours+1
if ( hours = 23 ) hours’ = 0
if ( selected = ‘MINS’ )
if ( mins< 59 ) mins’ = mins+1
if ( mins= 59 ) mins’ = 0
...
12. clock– scenario revisited
time is 22:58:33
user types: mode mode + +
action selected hours mins secs
NONE 22 58 33
mode
HRS 22 58 33
mode
MINS 22 58 33
increment (+)
MINS 22 59 33
increment (+)
MINS 22 0 33
but does this want
to become 23?
13. defining state
two problems:
• too little state
elements missing from specification
may be deliberate
e.g. dialogue level spec.
• too much state
too many states, too complex state
may be deliberate
redundancy, extensibility
14. too little state
forgotten elements
e.g. ‘selected’ mode in car clock
checking:
– dialogue state
can you work out current dialogue state?
– action specification
do you have enough information?
– implicit global variables (see also later)
suggest state missing
15. too much state
unreachable states
too few actions (see later)
constraints
spare variables: constant/functional dependent
dependent state
e.g. first point of line, number being typed
indistinguishable states
what is observable?
states are not orthogonal
16. defining actions
framing problems
= too little in result state
unreachable states – insufficient actions
using ‘global’ variables
implicit in operation definition
beware extreme cases
(e.g. empty document, cursor at end of line)
17. internal and external consistency
state
scenarios
actions
invariants preserved?
actions complete?
missing state?
makes sense?
general
properties
specific
examples