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

Conversation

nano-o
Copy link
Contributor

@nano-o nano-o commented Jan 22, 2024

As you can see it does not look as good as before. The string constants now all have the _OF_TYPE prefix. I'm not sure how to do better. @konnov any suggestion?

Signed-off-by: Giuliano Losa <giuliano@losa.fr>
@nano-o
Copy link
Contributor Author

nano-o commented Jan 22, 2024

I tried annotating all variables with the type Int -> Str, but then Apalache fails on the Spec == ... line.

COLORS == Permutation({ "red", "white", "blue", "green", "yellow" })
PETS == Permutation({ "bird", "cat", "dog", "fish", "horse" })
CIGARS == Permutation({ "blend", "bm", "dh", "pm", "prince" })
NATIONALITIES == Permutation({ "brit_OF_NATIONALITY", "swede_OF_NATIONALITY", "dane_OF_NATIONALITY", "norwegian_OF_NATIONALITY", "german_OF_NATIONALITY" })
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
NATIONALITIES == Permutation({ "brit_OF_NATIONALITY", "swede_OF_NATIONALITY", "dane_OF_NATIONALITY", "norwegian_OF_NATIONALITY", "german_OF_NATIONALITY" })
BRIT == "brit_OF_NATIONALITY"
SWEDE == "swede_OF_NATIONALITY"
DANE == "dane_OF_NATIONALITY"
NORWEGIAN == "norwegian_OF_NATIONALITY"
GERMAN == "german_OF_NATIONALITY"
NATIONALITIES == Permutation({ BRIT, SWEDE, DANE, NORWEGIAN, GERMAN })

Here is my suggestion on how to avoid specifying the type all the time.

@konnov
Copy link
Contributor

konnov commented Jan 22, 2024

Yeah, this looks like a lot of literals that are just screaming their types all the time. What you could do is to define a value for each literal and refer to that value. It will increase the size of the spec, but that's the easiest thing that comes to my mind:

https://github.com/tlaplus/Examples/pull/113/files#r1461491804

Copy link
Contributor

@konnov konnov left a comment

Choose a reason for hiding this comment

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

This looks like an interesting example for TLA+ and Apalache.

@@ -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) ==
Copy link
Contributor

Choose a reason for hiding this comment

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

Just by looking at the set of constraints, I think you could define Permutation for the general case too:

Permutation(S) ==
  { p \in [ House -> S ]:
    \A h1 \in House:
      \A h2 \in House:
        h2 /= h1 => p[h2] /= p[h1]
  }

You could even replace House with S, and it should still work in Apalache, as long as S is a finite set. Of course, this definition would produce really a lot of constraints, something like $O(|S|^{|House|}*|House|^2)$

@nano-o
Copy link
Contributor Author

nano-o commented Jan 22, 2024

I tried annotating all variables with the type Int -> Str, but then Apalache fails on the Spec == ... line.

@konnov is this a bug I should report?

Signed-off-by: Giuliano Losa <giuliano@losa.fr>
@nano-o
Copy link
Contributor Author

nano-o commented Jan 22, 2024

Now usingStr. This allows to use the same string constants as in the original version.

@konnov
Copy link
Contributor

konnov commented Jan 22, 2024

I tried annotating all variables with the type Int -> Str, but then Apalache fails on the Spec == ... line.

@konnov is this a bug I should report?

Yes, perhaps, something was missing in the annotations.

@nano-o nano-o marked this pull request as draft January 23, 2024 17:37
@nano-o nano-o marked this pull request as ready for review January 23, 2024 19:18
@nano-o
Copy link
Contributor Author

nano-o commented Jan 23, 2024

@lemmy is it acceptable to add type annotations to this spec or should they go into a separate file ApaEinstein.tla?

@lemmy
Copy link
Member

lemmy commented Jan 23, 2024

The specification might be easier to read if type annotations are placed in a separate file. Alternatively, enhanced IDE tools and pretty-printers could be used to minimize the visual impact of type annotations in comments, thereby preserving readability.

@nano-o
Copy link
Contributor Author

nano-o commented Jan 23, 2024

I'm not sure it will not be possible to move the annotation on vars to a separate file.

@ahelwer
Copy link
Collaborator

ahelwer commented Jan 23, 2024

I don't think this spec is useful without being checked by Apalache (since TLC just times out on the initial state iirc) so it seems okay to me to modify the spec itself.

Comment on lines 159 to 161
\* 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)

@ahelwer
Copy link
Collaborator

ahelwer commented Jan 27, 2024

Is this ready to be evaluated & merged or is it a draft pull request?

Signed-off-by: Giuliano Losa <giuliano@losa.fr>
@nano-o
Copy link
Contributor Author

nano-o commented Jan 27, 2024

Is this ready to be evaluated & merged or is it a draft pull request?

Yes this is ready to be evaluated and merged.

@ahelwer ahelwer merged commit 7db81cd into tlaplus:master Jan 29, 2024
4 checks passed
lemmy pushed a commit to lemmy/Examples that referenced this pull request Apr 5, 2024
Make Einstein work with Apalache

Signed-off-by: Giuliano Losa <giuliano@losa.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants