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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Copy link
Member

Choose a reason for hiding this comment

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

* Every node except the root has exactly one incoming edge
* Every node other than the root is reachable from the root

What about a forest?

Copy link
Author

Choose a reason for hiding this comment

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

you mean I should change the wording to forest or do you think I missed something?

Copy link
Member

Choose a reason for hiding this comment

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

Never mind, it appears as if the original definition is also false for a forest. It is probably a good idea to add tests that demonstrate the effects of your changes.

\* 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