Skip to content

Towards a TLAPS stdlib#127

Open
lemmy wants to merge 5 commits into
masterfrom
mku-stdlib
Open

Towards a TLAPS stdlib#127
lemmy wants to merge 5 commits into
masterfrom
mku-stdlib

Conversation

@lemmy

@lemmy lemmy commented Jul 9, 2026

Copy link
Copy Markdown
Member

This PR is the result of Opus 4.8 analyzing a large corpus of existing TLAPS proofs to identify recurring, broadly applicable proof obligations. Those common proof patterns have been extracted into reusable lemmas and added to the CommunityModules for wider reuse.

lemmy and others added 2 commits July 8, 2026 16:49
Add and prove membership theorems for SequencesExt!Contains
(empty/Append/Cons/Concat/Tail/singleton plus heterogeneous-type
Append/Concat variants) and SupersetOfMajorityIsMajority for
FiniteSetsExt. All obligations checked with TLAPS.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
Add SequencesExt!IsSorted(s, op(_,_)), which holds iff s is sorted with
respect to an arbitrary binary relation op, with a formal doc comment
and examples. Add and prove the accompanying theorems SortedEmpty,
SortedSingleton, SortedAppend, SortedConcat, SortedInjective and
SortedSubSeq, whose order hypotheses on op (transitivity, irreflexivity)
are stated locally so they apply to any relation. All obligations
checked with TLAPS.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the CommunityModules “stdlib” of reusable TLAPS lemmas by adding commonly needed theorems about sequence membership (Contains), sortedness (IsSorted), and a finite-set “majority” monotonicity property, along with accompanying TLAPS proofs.

Changes:

  • Added a new IsSorted predicate to SequencesExt plus supporting theorems (empty/singleton/append/concat/subseq) in SequencesExtTheorems.
  • Added a collection of Contains lemmas (including generalized heterogeneous variants) in SequencesExtTheorems, with proofs in the corresponding _proofs module.
  • Added a “superset of a majority is a majority” theorem to FiniteSetsExtTheorems, with a proof in the corresponding _proofs module.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
modules/SequencesExtTheorems.tla Adds new Contains and IsSorted theorem statements for reuse in other proofs.
modules/SequencesExtTheorems_proofs.tla Provides TLAPS proofs for the new Contains and IsSorted theorems (currently contains proof issues called out in comments).
modules/SequencesExt.tla Introduces the new IsSorted definition used by the added theorems.
modules/FiniteSetsExtTheorems.tla Adds a majority-related theorem statement (SupersetOfMajorityIsMajority).
modules/FiniteSetsExtTheorems_proofs.tla Adds the proof for SupersetOfMajorityIsMajority (currently missing key reasoning steps, called out in comments).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modules/SequencesExtTheorems_proofs.tla Outdated
Comment thread modules/SequencesExtTheorems_proofs.tla Outdated
Comment thread modules/SequencesExtTheorems_proofs.tla Outdated
Comment thread modules/FiniteSetsExtTheorems_proofs.tla

@muenchnerkindl muenchnerkindl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent initiative! I have a few comments, mainly suggestions for simpler proofs.


(*************************************************************************)
(* Any superset (within U) of a majority of U is itself a majority. *)
(*************************************************************************)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not, but in my experience a more abstract definition of a quorum system as sets (of processes) such that any two quorums intersect and closed under superset is easier to use. Something like

QuorumSystem(S) ==
    { QS \in SUBSET (SUBSET S) : 
          /\ QS # {}
          /\ \A Q1, Q2 \in QS : Q1 \cap Q2 # {}
          /\ \A Q1, Q2 \in SUBSET S : Q1 \in QS /\ Q1 \subseteq Q2 => Q2 \in QS
    }

One could then show that majorities constitute a quorum system, i.e.

THEOREM MajorityIsQS ==
    ASSUME NEW S, S # {}, IsFiniteSet(S)
    PROVE  { Q \in SUBSET S : 2 * Cardinality(Q) > Cardinality(S) } \in QuorumSystem(S)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread modules/FiniteSetsExtTheorems_proofs.tla
Comment thread modules/SequencesExtTheorems.tla Outdated
(* Membership in a sequence coincides with membership in its image set. *)
THEOREM ContainsToSet ==
ASSUME NEW S, NEW s \in Seq(S), NEW e
PROVE Contains(s, e) <=> e \in ToSet(s)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we prefer Range or ToSet?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

+1 Range

Comment thread modules/SequencesExtTheorems.tla Outdated

THEOREM ContainsSingleton ==
ASSUME NEW S, NEW x \in S
PROVE /\ << x >> \in Seq(S)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The first conjunct looks unnecessary to me, and it is only vaguely related to the statement of the theorem.

Comment thread modules/SequencesExtTheorems.tla Outdated
(* element type as the prefix, so these variants apply when the two sides *)
(* of a concatenation carry heterogeneous messages. *)
(***************************************************************************)
THEOREM ContainsAppendGen ==

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is just a reformulation of ContainsAppend. I don't understand what is meant by "generalized membership".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"element type", "heterogeneous messages" sounds like nonsense.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The theorems about "generalized" membership (including this one) were removed, and indeed these theorems became completely redundant after I removed some "type" assumptions from theorem statements. I just pushed a new version of SequencesExtTheorems.tla since I had forgotten to copy the relaxed theorem statements over from the _proofs module.


THEOREM SortedSingleton ==
ASSUME NEW S, NEW x \in S, NEW op(_,_)
PROVE IsSorted(<< x >>, op)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BY DEF IsSorted works.

Comment on lines +230 to +231
NEW e \in S, s # << >> => op(s[Len(s)], e)
PROVE IsSorted(Append(s, e), op)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BY DEF IsSorted works.

NEW s \in Seq(S), NEW t \in Seq(S),
IsSorted(s, op), IsSorted(t, op),
(Len(s) > 0 /\ Len(t) > 0) => op(s[Len(s)], t[1])
PROVE IsSorted(s \o t, op)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BY DEF IsSorted works.

ASSUME NEW S, NEW op(_,_),
\A x \in S : ~ op(x, x),
NEW s \in Seq(S), IsSorted(s, op)
PROVE IsInjective(s)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BY DEF IsSorted, IsInjective works.

ASSUME NEW S, NEW op(_,_),
NEW s \in Seq(S), IsSorted(s, op),
NEW m \in 1..Len(s)+1, NEW n \in 0..Len(s)
PROVE IsSorted(SubSeq(s, m, n), op)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BY DEF IsSorted works.

@lemmy

lemmy commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

@muenchnerkindl Do you want to take this PR over?

Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
@muenchnerkindl muenchnerkindl marked this pull request as ready for review July 10, 2026 18:46
@muenchnerkindl

Copy link
Copy Markdown
Contributor

@lemmy could you have a look and check?

…roofs module

Signed-off-by: Stephan Merz <stephan.merz@loria.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.

3 participants