The first argument to Cases need not have head List . Level specifications are described in Section A.3.6 . This command returns the summands that are powers. This returns the expressions that occur in the sum at any level and are powers.
Cases can also perform an arbitrary replacement in the terms that match the given pattern.
Here we pick all multiples of three, replacing them by their squares. This substitution can be useful, for example, in controlling recursion. Suppose we want to list all strings of length at most maxlen that are accepted by the automaton, that is, that do not take the automaton to the failure state. The function Useful tests whether or not a transition should be taken. The strings are grouped hierarchically.