Created
May 12, 2022 10:22
-
-
Save leiless/53893741b8367ac6bb803ac3e704e101 to your computer and use it in GitHub Desktop.
TLA+ PlusCal `transfer` module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---- MODULE transfer ---- | |
EXTENDS Naturals, TLC | |
(* --algorithm transfer | |
variables alice_account = 10, bob_account = 10, | |
account_total = alice_account + bob_account; | |
process Transfer \in 1..2 | |
variable money \in 1..20; | |
begin | |
A: | |
if alice_account >= money then | |
alice_account := alice_account - money; | |
bob_account := bob_account + money; | |
end if; | |
B: assert alice_account >= 0; | |
end process | |
end algorithm *) | |
MoneyNotNegative == money >= 0 | |
MoneyInvariant == alice_account + bob_account = account_total | |
==== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Final transfer algorithm to the https://learntla.com/introduction/example/