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

Tree check: cycle-free , rooted tree.. #94

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions modules/Graphs.tla
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ IsStronglyConnected(G) ==
-----------------------------------------------------------------------------
IsTreeWithRoot(G, r) ==
/\ IsDirectedGraph(G)
/\ \A e \in G.edge : /\ e[1] # r
/\ \A f \in G.edge : (e[1] = f[1]) => (e = f)
/\ \A n \in G.node : AreConnectedIn(n, r, G)
/\ (Cardinality(G.node) = 1 => G.node = {r})
\* Handles single-node tree case
/\ \A n \in G.node \ {r} : \E! f \in G.edge : f[2] = n
\* Every node except the root has exactly one incoming edge
/\ \A n \in G.node \ {r} : AreConnectedIn(r, n, G)
\* Every node other than the root is reachable from the root
/\ \A n \in G.node \ {r} : ~\E path \in SimplePath(G) : path[1] = n /\ path[Len(path)] = n
younes-io marked this conversation as resolved.
Show resolved Hide resolved
\* No cycles: No path from a node to itself

=============================================================================
\* Modification History
\* Last modified Sun Dec 24 14:31:00 CET 2023 by Younes Akhouayri
\* Last modified Sun Mar 06 18:10:34 CET 2022 by Stephan Merz
\* Last modified Tue Dec 21 15:55:45 PST 2021 by Markus Kuppe
\* Created Tue Jun 18 11:44:08 PST 2002 by Leslie Lamport
\* Created Tue Jun 18 11:44:08 PST 2002 by Leslie Lamport