meeting -*- Outline -*- * state transformers (5.1) goals: formalize notion of program variables in HOL formulate basic properties of program variables illustrate reasoning in HOL ------------------------------------------ STATES AND STATE TRANSFORMERS (CH 5) Ideas: Def: a *state space*, S, over a set of types X is a type environment whose types are drawn from X; i.e., a finite map from names to X. Example: Def: a *state*, s, of type S, s:S is a collection of attributes, such for all x:U in S, s has an attribute x of type U Example: Def: a state transformer, f: S -> T, is such that for all states s:S, f.s : T Example: ------------------------------------------ For state spaces (type envs) use capital greek letters. For types, use roman capitals (unlike book). ... {x: Int, y: Bool} is a state space over {Int, Bool} In a state space, think of the the variables are dimensions, the types are the "units" The state space is the type of a state. ... {x=3, y=tt} is a state of type {x: Int, y: Bool} Note: a state transformer maps all states of the given argument type to states of the result type. ... x := 3 is a state transformer of type {x: Int, y: Bool} -> {x: Int, y: Bool} (and other types as well, but at least it has this one) which maps {x=3, y=tt} to {x=5, y=tt} "begin var z:Int = 0" is a state transformer of type {x: Int, y: Bool} -> {x: Int, y: Bool, z:Int} (and other types as well, but at least it has this one) which maps {x=3, y=tt} to {x=3, y=tt, z=0} "end" is a state transformer of type {x: Int, y: Bool, z:Int} -> {x: Int, y: Bool} which maps {x=3, y=tt, z=0} to {x=3, y=tt} ------------------------------------------ TRAN State transformer category Objects: state spaces over a given set of types Arrows: state transformers Notation: category Tran has morphisms over set of types X X Hom-set ^ Tran (S,T) = S -> T X ------------------------------------------ Note that the objects aren't states, they are sets of states! So if f is a state transformer we can think of f as working like: f.{s1, ..., sn} == {f.s1, ..., f.sn} The idea is that a state transformer in Tran(S,T) works on all states of a given type, and only cares about the attributes. Q: What's the unit (1) of this category? Q: What's composition in this category? forward, diagram order, composition Q: What's an example? Let's take Tran_{Bool}, this has as objects state spaces whose variables have types Bool, such as {{x=tt}, {x=ff}}