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 2 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
22 changes: 18 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,13 @@ Init ==
/\ pets \in PETS
/\ cigars \in CIGARS

\* @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 +156,8 @@ Solution ==

FindSolution == ~Solution

\* To find the solution with the `^Apalache^' model-checker, run:
\* apalache-mc check --init=Init --inv=FindSolution --length=0 Einstein.tla
\* Then look for the file violation.tla in `^Apalache^' output directory.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case it is helpful, you can use the --run-dir flag to put the output (including the violation) in a known location:

 apalache-mc --help | grep 'run-dir'
   --run-dir            : additional directory wherein output files for this run will be written directly, default: none (overrides envvar RUN_DIR)


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