Skip to content

Commit

Permalink
Added Leslie's Paxos How To Win A Turing Award lecture
Browse files Browse the repository at this point in the history
  • Loading branch information
lamport authored and lemmy committed Aug 29, 2019
1 parent 9e4552b commit fca227e
Show file tree
Hide file tree
Showing 19 changed files with 1,192 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Do you have your own case study that you like to share with the community? Send
| 62 | Misra Reachability Algorithm | <a href="https://github.com/tlaplus/Examples/tree/master/specifications/MisraReachability">Misra Reachability Algorithm</a> | Leslie Lamport | &#10004; | &#10004; | Int, Seq, FiniteSets, TLC, TLAPS, NaturalsInduction |
| 63 | Loop Invariance | <a href="https://github.com/tlaplus/Examples/tree/master/specifications/LoopInvariance">Loop Invariance</a> | Leslie Lamport | &#10004; | &#10004; | Int, Seq, FiniteSets, TLC, TLAPS, SequenceTheorems, NaturalsInduction |
| 64 | Teaching Concurrency | <a href="https://github.com/tlaplus/Examples/tree/master/specifications/TeachingConcurrency">Teaching Concurrency</a> | Leslie Lamport | &#10004; | &#10004; | Int, TLAPS |
| 64 | Spanning Tree | <a href="https://github.com/tlaplus/Examples/tree/master/specifications/SpanningTree">Spanning Tree</a> | Leslie Lamport | | &#10004; | Int, FiniteSets, TLC, Randomization |
| 65 | Spanning Tree | <a href="https://github.com/tlaplus/Examples/tree/master/specifications/SpanningTree">Spanning Tree</a> | Leslie Lamport | | &#10004; | Int, FiniteSets, TLC, Randomization |
| 66 | Paxos (How to win a Turing Award) | <a href="https://github.com/tlaplus/Examples/tree/master/specifications/PaxosHowToWinATuringAward">Paxos</a> | Leslie Lamport | | &#10004; | Nat, Int, FiniteSets |


## License
Expand Down
Binary file not shown.
113 changes: 113 additions & 0 deletions specifications/PaxosHowToWinATuringAward/Consensus.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
----------------------------- MODULE Consensus ------------------------------
(***************************************************************************)
(* This is an very abstract specification of the consensus problem, in *)
(* which a set of processes must choose a single value. We abstract away *)
(* even the processes. We specify the simple requirement that at most one *)
(* value is chosen by describing the set of all chosen values. The naive *)
(* requirement is that this set never contains more than one value, which *)
(* is an invariance property. But a little thought shows that this *)
(* requirement allows a value to be chosen then unchosen, and then another *)
(* value to be chosen. So we specify that the set of chosen values is *)
(* initially empty, it can be set to a single value, and then it can never *)
(* change. *)
(* *)
(* We are ignoring liveness, so we do not any requirement that a value is *)
(* eventually chosen. *)
(***************************************************************************)

EXTENDS Naturals, FiniteSets
(*************************************************************************)
(* Imports standard modules that define operators of arithmetic on *)
(* natural numbers and the Cardinality operator, where Cardinality(S) is *)
(* the number of elements in the set S, if S is finite. *)
(*************************************************************************)
CONSTANT Value
(*************************************************************************)
(* The set of all values that can be chosen. *)
(*************************************************************************)
VARIABLE chosen
(*************************************************************************)
(* The set of all values that have been chosen. *)
(*************************************************************************)

(***************************************************************************)
(* The type-correctness invariant asserting the "type" of the variable *)
(* 'chosen'. It isn't part of the spec itself--that is, the formula *)
(* describing the possible sequence of values that 'chosen' can have in a *)
(* behavior correct behavior of the system, but is an invariance property *)
(* that the spec should satisfy. *)
(***************************************************************************)
TypeOK == /\ chosen \subseteq Value
/\ IsFiniteSet(chosen)

(***************************************************************************)
(* The initial predicate describing the possible initial state of *)
(* 'chosen'. *)
(***************************************************************************)
Init == chosen = {}

(***************************************************************************)
(* The next-state relation describing how 'chosen' can change from one *)
(* step to the next. Note that is enabled (equals true for some next *)
(* value chosen' of choseen) if and only if chosen equals the empty set. *)
(***************************************************************************)
Next == /\ chosen = {}
/\ \E v \in Value : chosen' = {v}

(***************************************************************************)
(* The TLA+ temporal formula that is the spec. *)
(***************************************************************************)
Spec == Init /\ [][Next]_chosen

-----------------------------------------------------------------------------
(***************************************************************************)
(* The specification should imply the safety property that 'chosen' can *)
(* contain at most one value in any reachable state. This condition on *)
(* the state is expressed by Inv defined here. *)
(***************************************************************************)
Inv == /\ TypeOK
/\ Cardinality(chosen) \leq 1

(***************************************************************************)
(* The following theorem asserts the desired safety propert. Its proof *)
(* appears after the theorem. This proof is easily checked by the TLAPS *)
(* prover. *)
(***************************************************************************)
THEOREM Invariance == Spec => []Inv
<1>1. Init => Inv

<1>2. Inv /\ [Next]_chosen => Inv'

<1>3. QED
BY <1>1, <1>2 DEF Spec

(***************************************************************************)
(* If you are reading this specification in the Toolbox as you should be *)
(* (either the source file or its pretty-printed version), then you have *)
(* already opened the specification in the Toolbox. If not, you should do *)
(* that now. Download and run the Toolbox. Open a new specification with *)
(* this module file (Consensus.tla) as the root file, using the default *)
(* specification name, which is the name of the root file. Along with the *)
(* module, this will install a TLC model named 3Values. Open that model. *)
(* You will see that the model specifies three things: *)
(* *)
(* - The specification is formula Spec. *)
(* *)
(* - Three unspecified constants a, b, and c (called model values) *)
(* are substituted for the declared constants Values. *)
(* *)
(* - TLC should check that formula Inv is an invariant (a *)
(* formula true on all reachable states of he specification. *)
(* *)
(* Run TLC on the model. For this tiny spec, this just takes perhaps a *)
(* millisecond plus the couple of seconds that TLC needs to start and stop *)
(* running any spec. *)
(* *)
(* TLC's default setting to check for deadlock would cause it to report a *)
(* deadlock because no action is possible after a value is chosen. We *)
(* would say that the system terminated, but termination is just deadlock *)
(* that we want to happen, and the model tells TLC that we want deadlock *)
(* by disabling its check for it. *)
(***************************************************************************)

=============================================================================
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Consensus</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>toolbox.builder.TLAParserBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>toolbox.natures.TLANature</nature>
</natures>
<linkedResources>
<link>
<name>Consensus.tla</name>
<type>1</type>
<locationURI>PARENT-1-PROJECT_LOC/Consensus.tla</locationURI>
</link>
</linkedResources>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ProjectRootFile=PARENT-1-PROJECT_LOC/Consensus.tla
eclipse.preferences.version=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.lamport.tla.toolbox.tool.tlc.modelCheck">
<stringAttribute key="configurationName" value="3Values"/>
<intAttribute key="distributedFPSetCount" value="0"/>
<stringAttribute key="distributedNetworkInterface" value="100.64.12.255"/>
<intAttribute key="distributedNodesCount" value="1"/>
<stringAttribute key="distributedTLC" value="off"/>
<intAttribute key="fpIndex" value="0"/>
<intAttribute key="maxHeapSize" value="25"/>
<stringAttribute key="modelBehaviorInit" value=""/>
<stringAttribute key="modelBehaviorNext" value=""/>
<stringAttribute key="modelBehaviorSpec" value="Spec"/>
<intAttribute key="modelBehaviorSpecType" value="1"/>
<stringAttribute key="modelBehaviorVars" value="chosen"/>
<stringAttribute key="modelComments" value="A simple model of our trivial spec, in which Value is assigned the value {a, b, c} for unspecified constants a, b, and c. It checks that Inv is an invariant. If 'Deadlock' hadn't been unchecked, TLC would report termination as deadlock."/>
<booleanAttribute key="modelCorrectnessCheckDeadlock" value="false"/>
<listAttribute key="modelCorrectnessInvariants">
<listEntry value="1Inv"/>
</listAttribute>
<listAttribute key="modelCorrectnessProperties"/>
<stringAttribute key="modelExpressionEval" value=""/>
<listAttribute key="modelParameterConstants">
<listEntry value="Value;;{a, b, c};1;0"/>
</listAttribute>
<intAttribute key="numberOfWorkers" value="2"/>
<stringAttribute key="result.mail.address" value=""/>
<stringAttribute key="specName" value="Consensus"/>
<stringAttribute key="tlcResourcesProfile" value="local custom"/>
</launchConfiguration>
Binary file not shown.
Loading

0 comments on commit fca227e

Please sign in to comment.