Decompose distinct

Depends on #317 , review after that one.
In general, the rules in rules.py are general transformation rules and may well conflict. Eg myria likes projecting join but grappa does not, so we have rules in both directions.