I created a model of a tree. See below. Is there a better model? By "better" I mean simpler.
sig Node {
tree: set Node
}
one sig root extends Node {}
fact {
// No node above root (no node maps to root)
no tree.root
// Can reach all nodes from root
all n: Node - root | n in root.^tree
// No node maps to itself (irreflexive)
no iden & tree
// No cycles
no n: Node | Node in n.^tree
// All nodes are distinct (injective)
tree.~tree in iden
}
What's not simple about this? You could simplify the constraints:
sig Node {
tree: set Node
}
one sig root extends Node {}
pred CostelloTree {
// No node above root (no node maps to root)
no tree.root
// Can reach all nodes from root
all n: Node - root | n in root.^tree
// No node maps to itself (irreflexive)
no iden & tree
// No cycles
no n: Node | Node in n.^tree
// All nodes are distinct (injective)
tree.~tree in iden
}
pred DJTree {
Node in root.*tree // all reachable
no iden & ^tree // no cycles
tree in Node lone -> Node // at most one parent
}
check {CostelloTree iff DJTree}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.