small performance fix

The change is necessary because Z3 substitutions reverse the
order of arguments of 'distinct'.