Guest User

TLA+ example

a guest
Jul 4th, 2020
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. EXTENDS Integers
  2.  
  3. (*--algorithm wire
  4. variables
  5. people = {"alice", "bob"},
  6. acc = [p \in people |-> 5],
  7. sender = "alice",
  8. receiver = "bob",
  9. amount = 3;
  10. define
  11. NoOverdrafts == \A p \in people: acc[p] >= 0
  12. end define;
  13. begin
  14. Withdraw:
  15. acc[sender] := acc[sender] - amount;
  16. Deposit:
  17. acc[receiver] := acc[receiver] + amount;
  18. end algorithm; *)
  19.  
  20. \* BEGIN TRANSLATION - the hash of the PCal code: PCal-e225ea799128c97770e0e93b60ab5c94
  21. VARIABLES people, acc, sender, receiver, amount, pc
  22.  
  23. (* define statement *)
  24. NoOverdrafts == \A p \in people: acc[p] >= 0
  25.  
  26. vars == << people, acc, sender, receiver, amount, pc >>
  27. Init == (* Global variables *)
  28. /\ people = {"alice", "bob"}
  29. /\ acc = [p \in people |-> 5]
  30. /\ sender = "alice"
  31. /\ receiver = "bob"
  32. /\ amount = 3
  33. /\ pc = "Withdraw"
  34.  
  35. Withdraw == /\ pc = "Withdraw"
  36. /\ acc' = [acc EXCEPT ![sender] = acc[sender] - amount]
  37. /\ pc' = "Deposit"
  38. /\ UNCHANGED << people, sender, receiver, amount >>
  39.  
  40. Deposit == /\ pc = "Deposit"
  41. /\ acc' = [acc EXCEPT ![receiver] = acc[receiver] + amount]
  42. /\ pc' = "Done"
  43. /\ UNCHANGED << people, sender, receiver, amount >>
  44.  
  45. (* Allow infinite stuttering to prevent deadlock on termination. *)
  46. Terminating == pc = "Done" /\ UNCHANGED vars
  47.  
  48. Next == Withdraw \/ Deposit
  49. \/ Terminating
  50.  
  51. Spec == Init /\ [][Next]_vars
  52.  
  53. Termination == <>(pc = "Done")
Advertisement
Add Comment
Please, Sign In to add comment