.. _section-Representing Actions: Representing Actions -------------------- We can use KB updates (:ref:`section-Knowledge Base Updates`) to represent the notion of *actions* with *preconditions* and *effects*, common in AI planning and related disciplines. For example, consider a “blocks world”, where we have some number of blocks that can be stacked on top of each other, or stay on the ground. We have one action, “put”, which attempts to put one block on top of one another. This should succeed only if both blocks are “free”, that is, they do not have another block on top of them. We can represent this set of rules as follows: .. code-block:: flora on(b1,b3). on(b3,b2). on(b2,ground). // A block is free if there is no other block on top of it. free(?b) :- \naf exists(?b2)^on(?b2,?b). // The ground is always free free(ground). // Put ?b1 on top of ?b2 %put(?b1,?b2) :- // preconditions free(?b1), free(?b2), on(?b1,?b3), // effects t_delete{on(?b1,?b3)}, t_insert{on(?b1,?b2)}. @!{Stack3} !- // Perform some actions %put(b1,ground), %put(b3,ground), %put(b2,b1), %put(b3,b2), // Check the end state on(b3,b2), on(b2,b1), on(b1,ground), free(b3), \naf free(b2), \naf free(b1). As in this example, actions typically both delete and insert facts in the KB. Note that this representation by itself does not give us the ability to search for sequences of actions that produce a given goal, i.e. automated planning. The action predicate, %put, is *procedural* (marked by %), for reasons explained in :ref:`section-Non-tabled Predicates`.