Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find solution to Einstein's riddle with Apalache #113

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions specifications/EinsteinRiddle/Einstein.tla
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@

EXTENDS Naturals, FiniteSets

House == 1..5

\* Note that TLC!Permutations has a Java module override and, thus,
\* would be evaluated faster. However, TLC!Permutations equals a
\* set of records whereas Permutation below equals a set of tuples/
\* sequences. Also, Permutation expects Cardinality(S) = 5.
Permutation(S) ==
{ p \in [ 1..5 -> S ] :
Permutation(S) ==
{ p \in [ House -> S ] :
/\ p[2] \in S \ {p[1]}
/\ p[3] \in S \ {p[1], p[2]}
/\ p[4] \in S \ {p[1], p[2], p[3]}
Expand All @@ -58,10 +60,15 @@ PETS == Permutation({ "bird", "cat", "dog", "fish", "horse" })
CIGARS == Permutation({ "blend", "bm", "dh", "pm", "prince" })

VARIABLES
\* @type: Int -> Str;
nationality, \* tuple of nationalities
\* @type: Int -> Str;
colors, \* tuple of house colors
\* @type: Int -> Str;
pets, \* tuple of pets
\* @type: Int -> Str;
cigars, \* tuple of cigars
\* @type: Int -> Str;
drinks \* tuple of drinks

------------------------------------------------------------
Expand Down Expand Up @@ -122,10 +129,15 @@ Init ==
/\ pets \in PETS
/\ cigars \in CIGARS

\* Apalache cannot infer the type of `vars' because it could be a sequence or a tuple.
\* So we explicitely tell Apalache that it is a sequence by adding the following annotation:
\* @type: Seq(Int -> Str);
vars == <<nationality, colors, cigars, pets, drinks>>

Next ==
UNCHANGED <<nationality, colors, cigars, pets, drinks>>
UNCHANGED vars

Spec == Init /\ [][Next]_<<nationality, colors, cigars, pets, drinks>>
Spec == Init /\ [][Next]_vars

Solution ==
/\ BritLivesInTheRedHouse
Expand All @@ -146,4 +158,8 @@ Solution ==

FindSolution == ~Solution

\* To find the solution with the `^Apalache^' model-checker, run:
\* `^apalache-mc check --init=Init --inv=FindSolution --length=0 --run-dir=./outout Einstein.tla^'
\* You will then find the solution in `^./output/violation.tla^'.

============================================================