Visualising Logic Production Systems programs

Let’s consider an implementation of the Game of Life in LPS, whose initial state leads to the appearance of a well-known pattern, the “blinker“. If you type go(T) in the query box you’ll get a timeline depicting fluents and actions:

Alive cells are represented by ‘-‘(X,Y) terms, births by live(Cell) and deaths by fire(Cell), over the 8 time cycles of the simulation.

This is precise, but a bit overwhelming. There’s an alternative visualisation, abstracting the above into a Deterministic Finite Automata – like, state transitions diagram. By using godfa(G) instead:

Arguably simpler to understand. Now, the Game of Life’s visual appeal did not emerge from geeky diagrams alike the above… but instead from the rendering of automata cells in their natural two-dimensional space. In order to get that, we need to add some information to the pure logic theory of the program, by telling LPS how to represent fluents and actions in space:

This d(Thing,Properties) meta predicate provides visualisation properties for their matching fluents and actions; so alive cells will be green circles with radius 5 pixels, birth and death will be explosion-like stars, etc.

By using go(T) again, the additional information is used to drive a PaperJS-based animation:

Actions are displayed transiently in the scene; the above single frame shows the black action of death killing two cells, while two reddish births occur, all over the live cell fluents in green. You can try all this by uncommenting lines 47-56 in http://demo.logicalcontracts.com/example/life.pl