Skip to content

Instantly share code, notes, and snippets.

@leiless
Created May 12, 2022 10:22
Show Gist options
  • Save leiless/53893741b8367ac6bb803ac3e704e101 to your computer and use it in GitHub Desktop.
Save leiless/53893741b8367ac6bb803ac3e704e101 to your computer and use it in GitHub Desktop.
TLA+ PlusCal `transfer` module
---- 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
====
@leiless
Copy link
Author

leiless commented May 12, 2022

Final transfer algorithm to the https://learntla.com/introduction/example/

# File -> TranslateCal Algorithm(Ctrl + T)

# What is the behavior spec?
# Temporal formula (Spec)

# What to check?
# Deadlock (checked)

# Invariants
# MoneyNotNegative (unchecked)
# MoneyInvariant (checked)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment