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:

Stylised subway-map diagram on a white background, drawn with thick coloured lines and small white station dots ringed in teal (#2f8576), station names in dark teal (#16433c). A horizontal blue line (#1565a8) with arrowheads runs left to right through three stations: Taipei Main Station, then Ximen, then Longshan Temple. From the Ximen station a green branch line (#1a8a4a) with arrowheads drops straight down through two more stations: Beimen, then Zhongshan. All arrows point in travel direction, away from Taipei Main Station.
roundnew pairsreach so far
1Taipei Main Station→Ximen, Ximen→Longshan Temple, Ximen→Beimen, Beimen→Zhongshan4 pairs
2Taipei Main Station→Longshan Temple, Taipei Main Station→Beimen, Ximen→Zhongshan7 pairs
3Taipei Main Station→Zhongshan8 pairs
4none8 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.