| Did you know ... | Search Documentation: |
| Predicate term_automaton/2 |
Automaton is a compound whose argument I is the colour of state I, and state 1 is the start state. An argument that is a compound gives the state one successor per argument of that compound, and the argument is the number of the state the successor goes to. An argument that is not a compound makes the state a sink holding that value. So a leaf is a state rather than an argument, which is why nothing in an argument position is ever anything but a state number:
?- term_automaton(f(g(a),g(a)), A). A = automaton(f(2, 3), g(4), g(4), a).
The translation is faithful in both directions: one state per physically distinct compound cell of Term and one per distinct leaf, sharing what Term already shares and collapsing nothing. Term may be cyclic, and so may Automaton:
?- X = f(X), term_automaton(X, A). A = automaton(f(1)).
The functor name of Automaton is not looked at when it is
read; like arg/3,
only the arity matters. The name used when it is written is always automaton.
Note that the value of a sink can never be a compound, so a state label
that is a compound has to be taken apart into states of its own.