WYRL: copied over code for canonicalisation from old automata library (#272)