A Tutorial Introduction to TLA+
Stephan Merz
http://www.loria.fr/˜merz/ INRIA Nancy & LORIA Nancy, France
TLA+ Community Event, ABZ 2014 Toulouse, June 3, 2014
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 1 / 39
Objective Explain basic concepts of TLA + modeling systems: static - - PowerPoint PPT Presentation
A Tutorial Introduction to TLA + Stephan Merz http://www.loria.fr/merz/ INRIA Nancy & LORIA Nancy, France TLA + Community Event, ABZ 2014 Toulouse, June 3, 2014 TLA + Tutorial Stephan Merz (INRIA Nancy) Toulouse, June 2014 1 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 1 / 39
◮ modeling systems: static and dynamic aspects ◮ existing tool support for modeling and analysis
◮ elementary aspects of system refinement
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 2 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 3 / 39
◮ nodes can be active (double circle) or inactive ◮ how can node 0 (master node) detect when all nodes are inactive? Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 4 / 39
◮ nodes can be active (double circle) or inactive ◮ how can node 0 (master node) detect when all nodes are inactive?
◮ initially: token at master node, who may pass it to its neighbor Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 4 / 39
◮ nodes can be active (double circle) or inactive ◮ how can node 0 (master node) detect when all nodes are inactive?
◮ initially: token at master node, who may pass it to its neighbor ◮ when a node is inactive, it passes on the token Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 4 / 39
◮ nodes can be active (double circle) or inactive ◮ how can node 0 (master node) detect when all nodes are inactive?
◮ initially: token at master node, who may pass it to its neighbor ◮ when a node is inactive, it passes on the token ◮ termination detected when token returns to inactive master node Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 4 / 39
◮ nodes can be active (double circle) or inactive ◮ how can node 0 (master node) detect when all nodes are inactive?
◮ initially: token at master node, who may pass it to its neighbor ◮ when a node is inactive, it passes on the token ◮ termination detected when token returns to inactive master node
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 4 / 39
◮ master node initiates probe by sending white token Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 5 / 39
◮ master node initiates probe by sending white token ◮ message to higher-numbered node stains sending node Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 5 / 39
◮ master node initiates probe by sending white token ◮ message to higher-numbered node stains sending node ◮ when passing the token, a black node stains the token Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 5 / 39
◮ master node initiates probe by sending white token ◮ message to higher-numbered node stains sending node ◮ when passing the token, a black node stains the token
◮ white token at inactive, white master node Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 5 / 39
◮ master node initiates probe by sending white token ◮ message to higher-numbered node stains sending node ◮ when passing the token, a black node stains the token
◮ white token at inactive, white master node
◮ safety:
◮ liveness: when all nodes inactive, termination will be detected Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 5 / 39
∆
∆
∆
∆
◮ sets Nodes and Color ◮ TypeOK documents expected values of variables ◮ active and color are arrays, i.e. functions Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 6 / 39
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 7 / 39
∆
∆
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 7 / 39
∆
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 8 / 39
∆
∆
∆
∆
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 8 / 39
1
◮ represent the state of the system by state variables ◮ mathematical abstractions: numbers, sets, functions, tuples, . . . Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 9 / 39
1
◮ represent the state of the system by state variables ◮ mathematical abstractions: numbers, sets, functions, tuples, . . . 2
◮ initial condition: state formula
◮ next-state relation: action formula constrains allowed transitions ◮ overall spec: temporal formula
◮ [Next]v
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 9 / 39
1
◮ represent the state of the system by state variables ◮ mathematical abstractions: numbers, sets, functions, tuples, . . . 2
◮ initial condition: state formula
◮ next-state relation: action formula constrains allowed transitions ◮ overall spec: temporal formula
◮ [Next]v
◮ formally, specify a universe that contains the modeled system ◮ use the power of mathematical logic to decompose the specification Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 9 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 10 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 11 / 39
1
◮ invariant of the specification:
◮ asserts that TypeOK is always true during any execution of Spec Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 12 / 39
1
◮ invariant of the specification:
◮ asserts that TypeOK is always true during any execution of Spec 2
◮ termination detected when white token at inactive, white node 0
∆
∆
◮ formally again expressed as an invariant Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 12 / 39
◮ instantiate system parameters by concrete values
◮ indicate operator corresponding to system specification
◮ indicate invariants to verify
◮ run TLC on this model and for these properties
◮ Eclipse IDE for developing and analyzing TLA+ specifications
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 13 / 39
◮ interesting specifications cannot be verified fully automatically
◮ user interaction guides verification ◮ automatic back-end provers discharge leaf obligations Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 16 / 39
◮ interesting specifications cannot be verified fully automatically
◮ user interaction guides verification ◮ automatic back-end provers discharge leaf obligations
∆
◮ hierarchical proof language represents proof tree ◮ steps can be proved in any order: usually start with QED step ◮ invariant follows from steps 11 and 12 by temporal logic Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 16 / 39
◮ definitions and facts must be cited explicitly ◮ this helps manage the size of the search space for backend provers Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 17 / 39
◮ definitions and facts must be cited explicitly ◮ this helps manage the size of the search space for backend provers
◮ back-end provers don’t prove this automatically ◮ use TLC to ensure that TypeOK is an inductive invariant
◮ decompose proof obligation into simpler steps Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 17 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 18 / 39
◮ TLC computes reachable state graph, checking invariants on the fly ◮ for termination, the set of reachable states must be finite ◮ updates of state variables: v′ = e or v′ ∈ E
◮ finite bounds for quantifiers, set comprehensions, function domains Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 19 / 39
◮ TLC computes reachable state graph, checking invariants on the fly ◮ for termination, the set of reachable states must be finite ◮ updates of state variables: v′ = e or v′ ∈ E
◮ finite bounds for quantifiers, set comprehensions, function domains
◮ explicit, hierarchical proofs ◮ inductive invariant must be provided by the user ◮ main proof effort at action level: supported by automatic backends ◮ PTL decision procedure for simple temporal reasoning Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 19 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 20 / 39
◮ expressed in TLA+ using a leadsto-formula F G
∆
∆
◮ verification using TLC, for 5 nodes Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 21 / 39
◮ expressed in TLA+ using a leadsto-formula F G
∆
∆
◮ verification using TLC, for 5 nodes ◮ TLC produces a counter-example that ends in infinite stuttering ◮ [Next]vars allows for steps that do not change vars
◮ fairness: action will be taken, provided it is long enough enabled
∆
◮ don’t stutter indefinitely as long as some transition is possible Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 21 / 39
◮ TLC verifies that the property is now satisfied Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 22 / 39
◮ TLC verifies that the property is now satisfied
∆
◮ our fairness requirement is too strong! ◮ weaken fairness constraint: only ensure termination detection
∆
∆
◮ TLC now verifies liveness, but no longer termination
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 22 / 39
◮ F can be a conjunction of weak or strong fairness conditions
∆
∆
∆
◮ typically: Next is a disjunction, fairness assumed for some disjuncts ◮ don’t assume too strong fairness conditions: use TLC for validation Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 23 / 39
◮ F can be a conjunction of weak or strong fairness conditions
∆
∆
∆
◮ typically: Next is a disjunction, fairness assumed for some disjuncts ◮ don’t assume too strong fairness conditions: use TLC for validation
◮ temporal properties such as P, P, P Q and combinations ◮ verification using TLC is more complex, but still automatic
◮ not yet supported by TLAPS: needs quantified temporal logic Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 23 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 24 / 39
◮ set-theoretical language for modeling data ◮ fair state machine specified in temporal logic Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 25 / 39
◮ set-theoretical language for modeling data ◮ fair state machine specified in temporal logic
◮ familiar presentations, using imperative-style language ◮ (obviously) effective for conveying algorithmic ideas ◮ neither executable nor mathematically precise
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 25 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 26 / 39
◮ use TLA+ expressions for modeling data ◮ simple translation of PlusCal to TLA+ specification
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 26 / 39
◮ use TLA+ expressions for modeling data ◮ simple translation of PlusCal to TLA+ specification
◮ flavor of imperative language: assignment, loop, conditional, . . . ◮ special constructs for non-deterministic choice
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 26 / 39
◮ use TLA+ expressions for modeling data ◮ simple translation of PlusCal to TLA+ specification
◮ flavor of imperative language: assignment, loop, conditional, . . . ◮ special constructs for non-deterministic choice
◮ statements may be labeled
◮ statements from one label to the next one are executed atomically Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 26 / 39
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 27 / 39
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 27 / 39
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 27 / 39
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 27 / 39
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 27 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 28 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 28 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 28 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 28 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 28 / 39
◮ variables corresponding to those declared in PlusCal algorithm ◮ “program counter” stores current point of program execution
∆
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 29 / 39
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 30 / 39
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 30 / 39
◮ transition relation of process: disjunction of individual transitions ◮ overall next-state relation: disjunction of processes ◮ generalizes to multiple instances of same process type
∆
∆
∆
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 31 / 39
◮ transition relation of process: disjunction of individual transitions ◮ overall next-state relation: disjunction of processes ◮ generalizes to multiple instances of same process type
∆
∆
∆
∆
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 31 / 39
◮ transition relation of process: disjunction of individual transitions ◮ overall next-state relation: disjunction of processes ◮ generalizes to multiple instances of same process type
∆
∆
∆
∆
∆
∆
∆
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 31 / 39
◮ retain familiar look and feel of pseudo-code ◮ abstractness and expressiveness through embedded TLA+ ◮ precision through simple translation to TLA+ ◮ formal verification via standard TLA+ tool set Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 32 / 39
◮ retain familiar look and feel of pseudo-code ◮ abstractness and expressiveness through embedded TLA+ ◮ precision through simple translation to TLA+ ◮ formal verification via standard TLA+ tool set
◮ single level of processes can make modeling unnatural ◮ translation dictates rules on where labels must and cannot go ◮ properties must be written in TLA+ (probably a feature) Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 32 / 39
◮ retain familiar look and feel of pseudo-code ◮ abstractness and expressiveness through embedded TLA+ ◮ precision through simple translation to TLA+ ◮ formal verification via standard TLA+ tool set
◮ single level of processes can make modeling unnatural ◮ translation dictates rules on where labels must and cannot go ◮ properties must be written in TLA+ (probably a feature)
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 32 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 33 / 39
◮ every behavior allowed by Impl is a possible execution of Spec ◮ TLA+ formalization
◮ systems and properties represented as formulas Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 34 / 39
◮ every behavior allowed by Impl is a possible execution of Spec ◮ TLA+ formalization
◮ systems and properties represented as formulas
◮ additional variables + extra transitions ◮ many steps of Impl will be meaningless for Spec Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 34 / 39
◮ every behavior allowed by Impl is a possible execution of Spec ◮ TLA+ formalization
◮ systems and properties represented as formulas
◮ additional variables + extra transitions ◮ many steps of Impl will be meaningless for Spec
◮ extra transitions of Impl stutter w.r.t. the variables in Spec ◮ stuttering steps are allowed by next-state relation [Next]vars ◮ infinite stuttering ruled out by fairness conditions Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 34 / 39
∆
∆
∆
∆
∆
∆
◮ new data may be sent when previous one has been received ◮ no explicit mechanism for transferring data Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 35 / 39
◮ for fixed instances of Data and constraints on channel size ◮ exercise: extend this to fair data transmission
◮ most transitions of alternating bit protocol stutter on sending, rcvd Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 36 / 39
◮ often introduce “implementation detail” for controlling transitions ◮ example: program counter generated by PlusCal translator ◮ internal detail should be hidden from “interface” Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 37 / 39
◮ often introduce “implementation detail” for controlling transitions ◮ example: program counter generated by PlusCal translator ◮ internal detail should be hidden from “interface”
∆
∆
◮ behaves like inner specification, but with variables x hidden Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 37 / 39
◮ often introduce “implementation detail” for controlling transitions ◮ example: program counter generated by PlusCal translator ◮ internal detail should be hidden from “interface”
∆
∆
◮ behaves like inner specification, but with variables x hidden
◮ prove Impl ⇒ Inner[t/x] for showing Impl ⇒ Spec ◮ refinement mapping t : computed from implementation variables Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 37 / 39
◮ describe system behavior at appropriate level of abstraction ◮ mathematical logic is flexible and expressive ◮ set theory plus state machine plus temporal logic ◮ no formal distinction between systems and properties ◮ experience shows that this approach scales to practical systems
◮ TLA+ Toolbox: editor, syntax/semantic analysis, pretty printer ◮ TLC: explicit-state model checker, checkpointing, parallelization ◮ TLAPS: interactive proof platform with powerful theorem provers ◮ PlusCal translator for generating TLA+ specification
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 38 / 39
Stephan Merz (INRIA Nancy) TLA+ Tutorial Toulouse, June 2014 39 / 39