several theorems about graphs#125
Conversation
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
|
OK, I should have realized that the operators must be renamed in the test module for the tests to work. |
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
|
@lemmy could you please have a look? I'd be particularly interested in your comments on my changes to existing operators. |
|
LGTM. However, wouldn't it be better to override the new generic operators using Java module overrides instead of introducing separate MC* definitions? That would free users from redefining the operators while still giving TLC an efficient definition, and follow the same approach already used elsewhere in this repository. |
|
Agreed, will try to do that. |
|
I will open a new draft PR soon with the three overrides. |
|
Also note that the definition of |
The amended definition now differs from https://github.com/tlaplus/Examples/blob/47b0e2cc0268836b89f5ce451f38e5df5f1cf773/specifications/SpecifyingSystems/AdvancedExamples/Graphs.tla#L29-L33. Perhaps, we should also amend SS def? Also, we should check if https://github.com/tlaplus/Examples/blob/master/specifications/ewd687a/EWD687a_proof.tla#L789 still proves and TLC continues to check the corresponding spec. |
|
Oh, I had not realized that Graphs was part of Specifying Systems ... As for EWD687a, I have a complete proof of the safety property (amended for the changed definition of IsTreeWithRoot) and will open a PR as soon as this one is settled. |
|
@muenchnerkindl Are you also going to align the defs in https://github.com/tlaplus/CommunityModules/blob/master/modules/UndirectedGraphs.tla? |
Check the operators exhaustively against their pure TLA+ definitions and the ConnectionsIn oracle over all graphs on up to three nodes, plus edge cases (self-loops, arguments outside the node set, composite/non-normalized node values). [Tests] Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
…nglyConnected
Register three Java overrides in TLCOverrides. SimplePath enumerates
simple paths via DFS instead of materializing SeqOf(node, Cardinality(node));
AreConnectedIn and IsStronglyConnected use BFS (the latter forward and on the
transpose) rather than the quadratic all-pairs pure-TLA+ definitions.
The overrides cut GraphsTests (exhaustive checks over all graphs on up to
four nodes `\cup Graphs({1, 2, 3})`) from ~15 to ~5 minutes.
TLC's code is not reused: its only Value-based graph algorithm,
TransitiveClosure.Warshall, is non-reflexive, drops isolated nodes and is
O(V^3), so it fits none of these operators.
[TLC]
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
* Theorems about Contains and majority supersets 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> * IsSorted operator and sortedness theorems 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> * theorems about sequences, finite sets, and quorum systems Signed-off-by: Stephan Merz <stephan.merz@loria.fr> * fixing two apparently brittle proofs Signed-off-by: Stephan Merz <stephan.merz@loria.fr> * align theorem statements in SequencesExtTheorems with those in the _proofs module Signed-off-by: Stephan Merz <stephan.merz@loria.fr> --------- Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de> Signed-off-by: Stephan Merz <stephan.merz@loria.fr> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Stephan Merz <stephan.merz@loria.fr>
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
|
@lemmy I believe that the Graphs and UndirectedGraphs modules are now in a state to be merged, could you please have a look? As for https://github.com/tlaplus/Examples/blob/47b0e2cc0268836b89f5ce451f38e5df5f1cf773/specifications/SpecifyingSystems/AdvancedExamples/Graphs.tla#L29-L33, I suggest not to change the definitions there (which would rewrite history) but to add a comment that a more recent Graphs module can be found here. |
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
| /\ p # << >> | ||
| /\ Cardinality({ p[i] : i \in DOMAIN p }) = Len(p) | ||
| /\ \A i \in 1..(Len(p)-1) : <<p[i], p[i+1]>> \in G.edge} | ||
| \* NB: TLC uses a Java override instead of this definition, |
There was a problem hiding this comment.
The TLA+ modules of the standard operators include a general note about overrides instead of repeating it.
|
|
||
| ----------------------------------------------------------------------------- | ||
| (****************************************************************************) | ||
| (* The set of all possible undirecteddirected graphs whose node set is S. *) |
| @@ -1,5 +1,5 @@ | |||
| ---------------------------- MODULE SequencesExt ---------------------------- | |||
| EXTENDS Sequences, Naturals, FiniteSets, FiniteSetsExt, Folds, Functions, Bags | |||
| EXTENDS Sequences, Naturals, FiniteSets, FiniteSetsExt, Folds, Functions, Bags, TLC | |||
There was a problem hiding this comment.
Not a blocker for this PR, but perhaps, we should consider adding preliminary support to TLAPS to handle the instantiation of constant-level/variable-free modules. This would prevent the namespace from becoming cluttered. Since CommunityModules are becoming TLA+’s standard library, EXTENDS will cause too many problems in the future.
| } | ||
|
|
||
| /* | ||
| * Compute the strongly connected components of an undirected graph: initially |
There was a problem hiding this comment.
Should "strongly" be removed here?
| PROVE IsDirectedGraph(Transpose(G)) | ||
|
|
||
| \* Note that the reverse implication does not hold in general. | ||
| \* Consider G = [node |-> {1}, edge |-> {<<1,1,1}>>, root |-> {1}] |
| IN { S \in SUBSET G.node : | ||
| /\ IsCC(S) | ||
| /\ \A T \in (SUBSET S) \ {S} : ~ IsCC(T) | ||
| /\ \A T \in SUBSET G.node : S \subseteq T /\ S # T => ~ IsCC(T) |
There was a problem hiding this comment.
I'd suggest adding theorems that fail to prove for the initial, broken definition.
… undirected graph modules Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
lemmy
left a comment
There was a problem hiding this comment.
LGTM - I had AI refactor the two overrides to share code (last commit).
This PR adds a number of theorems about graphs, including those required for the safety proof of the Dijkstra-Scholten algorithm (https://github.com/tlaplus/Examples/tree/master/specifications/ewd687a). I'll do a PR for that proof once these theorems are in.
Besides changing some (LOCAL) INSTANCE to EXTENDS due to current limitations of the PM – including in some modules imported here – I also made a few changes to Graphs.tla:
SimplePathand renamed the old definition toMCSimplePath: it applies only to finite graphs but can be evaluated by TLC,AreConnectedInandIsStronglyConnected,IsTreeWithRootso that it requires the root to be a node in the graph: the previous definition was vacuously true for an graph with an empty set of nodes, for any root, and this requires case distinctions when adding a new leaf to a tree. IMHO the present definition is reasonable and more uniform.The above changes may break some existing specification projects in that
SimplePathshould be overridden byMCSimplePathetc. when using TLC.I also noticed that the definition of
TransitiveClosureinRelations.tlais correct only for finite relations and suggest to eventually make analogous changes there, introducing an operatorMCTransitiveClosure.