'Make pattern-tree tips point to same object if they are equal.'

def fix_identities(self, uniq=None):

    if (not hasattr(self, 'children')):
        return self
    uniq = (list(set(self.flat())) if (uniq is None) else uniq)
    for (i, child) in enumerate(self.children):
        if (not hasattr(child, 'children')):
            assert (child in uniq)
            self.children[i] = uniq[uniq.index(child)]
        else:
            child.fix_identities(uniq)
