Thanks very much for all your suggestions - Peter, Duncan and Frederic. It was a great help.
Incidentally the question arose while I was trying to solve the 2-nots problem, http://www.inwap.com/pdp10/hbaker/hakmem/boolean.html#item19 Part of my program takes a set of boolean expressions in 3 variables and keeps concatenating them with 'and' and 'or' until all unique functions have been found. Sometimes it is good to use substitutions (though not required) to make the patterns apparent. Anyway, the listing is here, http://www.ocf.berkeley.edu/~abhishek/twonot3.py Abhishek -- http://mail.python.org/mailman/listinfo/python-list