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

Starting the document on TLA+ idioms #325

Merged
merged 14 commits into from
Nov 18, 2020
Merged

Starting the document on TLA+ idioms #325

merged 14 commits into from
Nov 18, 2020

Conversation

konnov
Copy link
Collaborator

@konnov konnov commented Nov 8, 2020

This document has been living in a separate branch for several months. Let's start writing it. The first two idioms are in.

docs/idiomatic/000keep-minimum-state-variables.md Outdated Show resolved Hide resolved
docs/idiomatic/000keep-minimum-state-variables.md Outdated Show resolved Hide resolved
docs/idiomatic/000keep-minimum-state-variables.md Outdated Show resolved Hide resolved
docs/idiomatic/README.md Outdated Show resolved Hide resolved
docs/idiomatic/README.md Outdated Show resolved Hide resolved
docs/idiomatic/README.md Outdated Show resolved Hide resolved
docs/idiomatic/README.md Outdated Show resolved Hide resolved
docs/idiomatic/README.md Outdated Show resolved Hide resolved
Shon, thanks for the comments!

Co-authored-by: Shon Feder <shon@informal.systems>
docs/idiomatic/README.md Outdated Show resolved Hide resolved
@lemmy
Copy link
Contributor

lemmy commented Nov 13, 2020

Perhaps, the definition of NotifyOther below could serve as an example of when to add additional variables to make a spec human-friendly:

--------------------------- MODULE BlockingQueueFair ---------------------------

...

VARIABLES buffer, waitSeq
vars == <<buffer, waitSeq>>


Range(f) == { f[i]: i \in DOMAIN f }
waitSet == Range(waitSeq)

RunningThreads == (Producers \cup Consumers) \ waitSet

NotifyOther(t) == 
          LET S == IF t \in Producers THEN waitSet \ Producers ELSE waitSet \ Consumers
              R == SelectSeq(waitSeq, LAMBDA u:u \in S)
              T == SelectSeq(waitSeq, LAMBDA u:u \notin S)
          IN IF R # <<>>
             THEN waitSeq' = Tail(R) \o T
             ELSE UNCHANGED waitSeq

(* @see java.lang.Object#wait *)
Wait(t) == /\ waitSeq' = Append(waitSeq, t)
           /\ UNCHANGED <<buffer>>
           
-----------------------------------------------------------------------------

Put(t, d) ==
   \/ /\ Len(buffer) < BufCapacity
      /\ buffer' = Append(buffer, d)
      /\ NotifyOther(t)
   \/ /\ Len(buffer) = BufCapacity
      /\ Wait(t)
      
Get(t) ==
   \/ /\ buffer # <<>>
      /\ buffer' = Tail(buffer)
      /\ NotifyOther(t)
   \/ /\ buffer = <<>>
      /\ Wait(t)

...
=============================================================================

In contrast, this is the variant with one more variable that separates wait into Producers and Consumers.

@konnov
Copy link
Collaborator Author

konnov commented Nov 16, 2020

Nice example, @lemmy. It indeed looks cleaner with one more variable. By the way, I am also violating this rule from time to time :-)

Copy link
Contributor

@adizere adizere left a comment

Choose a reason for hiding this comment

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

Very cool!

I initially wanted to ask if this repo is the right place to collect the idioms (VDD might have been better), but I understand that some idioms are actually Apalache-specific.

docs/idiomatic/001assignments.md Outdated Show resolved Hide resolved
docs/idiomatic/000keep-minimum-state-variables.md Outdated Show resolved Hide resolved
docs/idiomatic/001assignments.md Outdated Show resolved Hide resolved
konnov and others added 4 commits November 18, 2020 17:01
Yes! That sounds good!

Co-authored-by: Shon Feder <shon@informal.systems>
Co-authored-by: Adi Seredinschi <adi@informal.systems>
Co-authored-by: Adi Seredinschi <adi@informal.systems>
Co-authored-by: Adi Seredinschi <adi@informal.systems>
@konnov
Copy link
Collaborator Author

konnov commented Nov 18, 2020

I will merge this PR so it becomes more visible. Feel free to propose changes.

@konnov konnov merged commit 1e4bca0 into unstable Nov 18, 2020
@konnov konnov deleted the ik/idiomatic-tla branch November 18, 2020 16:12
@lemmy
Copy link
Contributor

lemmy commented Nov 18, 2020

Perhaps, auxiliary (history/prophecy) variables deserve mention too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants