Hint
There are again two ways of describing what the predicate has to
do. The declarative way states what properties two lists have to
have in order for the predicate replace_a_b_c
to be
true. The declarative way says what has to be done to the input
list in order to transform it into the output list. These are,
of course, just two ways of describing the same predicate
definition.
Under the declarative point of view, the predicate should be true when both lists are empty. It should also be true in the following four cases:
-
The first element of the input list is an a, the first
element of the output list is a b and the predicate
replace_a_b_c
is true when applied to the tails of the input list and the output list. -
The first element of the input list is an b, the first
element of the output list is a c and the predicate
replace_a_b_c
is true when applied to the tails of the input list and the output list. -
The first element of the input list is an c, the first
element of the output list is a a and the predicate
replace_a_b_c
is true when applied to the tails of the input list and the output list. -
The first element of the input list and the first
element of the output list are the same and the predicate
replace_a_b_c
is true when applied to the tails of the input list and the output list.
The procedural description goes as follows: if the input is an empty list, then there is nothing to replace; output the empty list. If the input is a non-empty list, then there are four cases that you have to deal with. The first element can be an a, b, or c, or neither of them. In the first three cases, specify that the first element of output list is a b, c, or a, respectively and treat the tail of the input list in the same way. The tail of the output list has to be what you get when replacing the a's, b's, and c's of the tail of the input list. If the fourth case (the first element is neither an a, nor a b, nor a c), specify that the first element of the output list is the same as the first element of the input list. And replace all a's, b's, and c's of the tail of the input list.