Rafael Luque / @osoco
int i ;
void main()
{ i = someNumber () ;
i = i + 1 ;
}
--------------------------- MODULE SimpleProgram ---------------------------
EXTENDS Integers
VARIABLES i, pc
Init == (pc = "start") /\ (i = 0)
Pick == \/ /\ pc = "start"
/\ i' \in 0..1000
/\ pc' = "middle"
Add1 == \/ /\ pc = "middle"
/\ i' = i + 1
/\ pc' = "done"
Next == \/ Pick
\/ Add1
=============================================================================
Write the TLA+ specification to compute the GCD with the Euclid's algorithm.
Computes GCD of M and N by:
Check your solution with TLC model checker to compute the GCD of inputs.
------------------------------- MODULE Euclid -------------------------------
EXTENDS Integers
CONSTANTS M, N
VARIABLES x, y
Init == (x = M) /\ (y = N)
Next == \/ /\ x < y
/\ y' = y - x
/\ x' = x
\/ /\ y < x
/\ x' = x-y
/\ y' = y
Spec == Init /\ [][Next]_<>
=============================================================================
Water Jug problem of Die Hard 3
------------------------------ MODULE DieHard ------------------------------
EXTENDS Naturals
VARIABLES big, \* The number of gallons of water in the 5 gallon jug.
small \* The number of gallons of water in the 3 gallon jug.
TypeOK == /\ small \in 0..3
/\ big \in 0..5
Init == /\ big = 0
/\ small = 0
FillSmallJug == /\ small' = 3
/\ big' = big
FillBigJug == /\ big' = 5
/\ small' = small
EmptySmallJug == /\ small' = 0
/\ big' = big
EmptyBigJug == /\ big' = 0
/\ small' = small
Min(m,n) == IF m < n THEN m ELSE n
SmallToBig == /\ big' = Min(big + small, 5)
/\ small' = small - (big' - big)
BigToSmall == /\ small' = Min(big + small, 3)
/\ big' = big - (small' - small)
Next == \/ FillSmallJug
\/ FillBigJug
\/ EmptySmallJug
\/ EmptyBigJug
\/ SmallToBig
\/ BigToSmall
Spec == Init /\ [][Next]_<>
=============================================================================
“Formal methods find bugs in system designs that cannot be found through any other technique we know of.”
“At Amazon, formal methods are routinely applied to the design of complex real-world software, including public cloud services.”
“A precise, testable description of a system becomes a whatif tool for designs, analogous to how spreadsheets are a what-if tool for financial models.”
“Executive management actively encourages teams to write TLA+ specs for new features and other significant design changes.”
Este obra está bajo una licencia de Creative Commons Reconocimiento-CompartirIgual 4.0 Internacional.