Let us compute the distance between the initial and the goal state. The initial state consists of the following set of facts:
( (*on a table) (clear a*) (*on b table*) (*on c b) (clear c*) )1 As it results from Table 1, all the initial state facts are related to (*on c b*), whereas (*on c b*) is not related to any other fact. Thus, in the first iteration of the AGGREGATION loop, M2 is set to ((on c b)) (step 2a) and M3 is set to ((*on a table*) (*clear a*) (*on b table) (clear c*)) (step 2b). So, *Cost* becomes equal to the distance of (*on c b*), i.e. 3 (step 2c) and M1 becomes empty. A second iteration is not performed and value 3, which is the actual distance between the initial and the goal state, is returned.

| Fact         | Distance from goals   | Related facts                                     |
|--------------|-----------------------|---------------------------------------------------|
| (on c table) | 0                     | ( )                                               |
| (on b c)     | 0                     | ( )                                               |
| (on a b)     | 0                     | ( )                                               |
| (clear a)    | 0                     | ( )                                               |
| (on a table) | 1                     | ( (clear b) )                                     |
| (clear B)    | 1                     | ( (on a table) )                                  |
| (on b table) | 2                     | ( (on a table) (clear a) (clear b) (clear c) )    |
| (clear c)    | 2                     | ( (on a table) (clear a) (clear b) (on b table) ) |
| (on c b)     | 3                     | ( (on a table) (clear a) (on b table) (clear c) ) |
| ...          | ...                   | ...                                               |

Corollary 3 ensures that set M2 (step 2a of function AGGREGATE) will never be empty. 

Proposition 4 ensures that M2 can always be partitioned in groups of facts that have been achieved by the same action (step 2c). The number of iterations that function AGGREGATE performs is bounded by the initial size of M1, however usually a single iteration is performed.

## 2.4 The Pre-Processing Algorithm

The estimation of the distance between each fact and the *Goals* and the computation of the lists of the related facts for each facts of a problem are performed through the following algorithm: