How it builds up
reach is a set of (from, to) pairs.
Datalog computes it in rounds, re-applying the rules until no new pairs appear:
| round | new pairs | reach so far |
|---|---|---|
| 1 | Taipei Main Station→Ximen, Ximen→Longshan Temple, Ximen→Beimen, Beimen→Zhongshan | 4 pairs |
| 2 | Taipei Main Station→Longshan Temple, Taipei Main Station→Beimen, Ximen→Zhongshan | 7 pairs |
| 3 | Taipei Main Station→Zhongshan | 8 pairs |
| 4 | none | 8 pairs: stop |
Each round feeds the previous round's
reach facts back into the recursive rule.
This “apply the rules until nothing changes” procedure is the heart of recursion in Datalog.