Skip to content

Conversation

@JarodDif
Copy link
Contributor

This PR contains two specifications created for my Master's thesis that could interest the community.

  1. The specification of the implementation of a barrier and the refinement towards an abstract one.
  2. The usage of auxiliary variables to achieve two-way refinement between Peterson's algorithm and an abstract lock

The specifications have not been added to the CI.

@ahelwer
Copy link
Collaborator

ahelwer commented Jul 26, 2025

Thank you for the contributions! Could you please greatly expand both of the READMEs? It should be very clear what each spec is about.

Copy link
Collaborator

@muenchnerkindl muenchnerkindl left a comment

Choose a reason for hiding this comment

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

Thanks for these contributions. In particular, the one that constructs a refinement from the two-process lock algorithm to Peterson shows how TLA+ can be used for proving trace equivalence between a high-level and a low-level spec. Although I appreciate your use of TLAPS throughout the developments, I'd suggest to include a few more sanity checks using TLC. Also, morally one assumption should be turned into a theorem (and it is actually true).

Finally, did you try to add your examples to manifest.json and to the top-level README.md? (If you find it too tricky, we can do it for you.)

A refinement towards an abstract Barrier specification is proven with TLAPS.

The main invariant `Inv` is verified in the provided model for $N = 7$
processes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Barriers.tla proves other invariants as well, perhaps they could be included in the configuration? And the proof in Barriers.tla culminates in verifying refinement between the two specifications, TLC could also be used to check this for a finite instance.


## Barrier.tla

A specification of an abstract Barrier. No model is provided. No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it make sense to have TLC check a basic property of that specification as well?

VARIABLE s
INSTANCE Stuttering

ASSUME AltStutterConstantCondition(1..2, 1, LAMBDA j : j-1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this an assumption? The predicate boils down to
ReachBot[{1}] = 1 .. 2
(with ReachBot defined in the definition of the predicate) and indeed a quick calculation shows that
ReachBot[{1}] = ReachBot[{1,2}] = {1,2}
so the condition holds, so this should really be a theorem. The TLAPS proof of that theorem may be tricky because it involves a recursive function (which, moreover, is defined inside a LET), if you have trouble with it, I can have a try at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could not write a proof for this property, as my knowledge of recursive definitions in TLA+ are lacking.

I would gladly accept some help for this.

## Peterson.tla

The specification of Peterson's algorithm in PlusCal, and the refinement proof
towards `Lock!Spec`
Copy link
Collaborator

Choose a reason for hiding this comment

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

This refinement could also be checked using TLC.


The extension of `Lock.tla` using a history variable `h_turn` and a stutter
variable `s`, provided by the `Stuttering.tla` module.
A refinement proof towards `Peterson!Spec` is presented within.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, it would make sense to use TLC for checking the different theorems proved in this module?

@JarodDif
Copy link
Contributor Author

I tried to improve the READMEs and the different models.
I'm still unsure if the models I provided to verify refinements are correct / follow best practices.

Concerning manifest.json, the sheer size of the manifest-schema makes me reticent to try and modify it myself.

Copy link
Collaborator

@muenchnerkindl muenchnerkindl left a comment

Choose a reason for hiding this comment

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

Thanks for your changes in reply to my previous comments! I added a few final suggestions: some possible additional explanations and perhaps remove the "MC..." module (and integrate the checks into the corresponding base models) whose purpose is not clear to me. It's really up to you if you want to take up these suggestions or not.

@@ -0,0 +1,6 @@
------------------------------- MODULE MCBarriers ------------------------------
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you really need this module? Usually "MC..." modules are introduced for specializing definitions or introducing additional bounds for model checking, but this is not done here. It looks like you could just add the definition to Barriers.tla and the property to Barriers.cfg?


(**
--algorithm Barrier {
variables
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would help the reader if you could add comments describing the purpose of these variables and the basic structure of the algorithm.


TypeOK ==
/\ pc \in [ProcSet -> {"b0", "b1"}]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps it would make sense to add the property
[][\A p,q \in ProcSet : pc[p] = "b0" /\ pc[q] = "b1" => pc'[q] = "b1"]_vars
that describes the idea of the barrier?

A model `MCBarriers.cfg` and its companion `MCBarriers.tla` verifies if
`B!Spec` (the abstract Barrier specification) holds for `Spec`

## Barrier.tla
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would make sense to talk about Barrier.tla before Barriers.tla – in particular since you mention it in the "Refinement" section.


The usual typing invariant is defined.

A model with the same amount of processes as above is provided. No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

amount -> number (counted, not weighed)

@@ -0,0 +1,7 @@
------------------------------- MODULE MCLockHS -------------------------------
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, I wonder why you choose to introduce a separate module for this, given that you already use the model checker on the base LockHS module.

@@ -0,0 +1,6 @@
------------------------------ MODULE MCPeterson ------------------------------
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question here: I'd remove this module and include the check in the base Peterson.cfg model.

VARIABLE s
INSTANCE Stuttering

THEOREM StutterConstantCondition(1..2, 1, LAMBDA j : j-1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps add a comment saying that this theorem justifies the introduction of s as a stuttering variable in action l1HS below?

Copy link
Collaborator

@muenchnerkindl muenchnerkindl left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@ahelwer
Copy link
Collaborator

ahelwer commented Jul 31, 2025

This repository requires DCO signoff on all commits.

@ahelwer
Copy link
Collaborator

ahelwer commented Jul 31, 2025

I opened PR JarodDif#1 which should add these specs to CI validation.

@ahelwer
Copy link
Collaborator

ahelwer commented Jul 31, 2025

Some issues with past model names being fixed in #179. @JarodDif would you be able to remove the PR changes I sent you then force-push to this branch to avoid merge conflicts?

@ahelwer
Copy link
Collaborator

ahelwer commented Jul 31, 2025

To avoid other weird merge conflicts it's fine to merge this with .ciignore entries in place then I'll add the specs to CI validation later. The specs will have to be removed from the README table for now.

@JarodDif
Copy link
Contributor Author

Would this suffice ?

@ahelwer
Copy link
Collaborator

ahelwer commented Jul 31, 2025

Yes, the CI will probably now pass. You still need to add DCO signoff to all your commits (see instructions provided by github here: https://github.com/tlaplus/Examples/pull/177/checks?check_run_id=47140681764) and expand the READMEs.

@ahelwer
Copy link
Collaborator

ahelwer commented Aug 6, 2025

Looks good! Just clear up that sentence fragment in the barriers README and I will merge.

@JarodDif
Copy link
Contributor Author

JarodDif commented Aug 6, 2025

This should fix the incomplete sentence.

Thank you for your time and help.

@ahelwer ahelwer merged commit 11c7cd8 into tlaplus:master Aug 7, 2025
7 checks passed
@ahelwer
Copy link
Collaborator

ahelwer commented Aug 7, 2025

Thank you for the wonderful examples!

ahelwer added a commit to ahelwer/Examples that referenced this pull request Aug 8, 2025
Specs were added in tlaplus#177

Signed-off-by: Andrew Helwer <[email protected]>
ahelwer added a commit to ahelwer/Examples that referenced this pull request Aug 8, 2025
Specs were added in tlaplus#177

Signed-off-by: Andrew Helwer <[email protected]>
ahelwer added a commit to ahelwer/Examples that referenced this pull request Aug 8, 2025
Specs were added in tlaplus#177

Signed-off-by: Andrew Helwer <[email protected]>
ahelwer added a commit that referenced this pull request Aug 8, 2025
Specs were added in #177

Signed-off-by: Andrew Helwer <[email protected]>
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.

4 participants