fix Dummy.sort_key and use it in expr.sort_key

Also, catch any new Numbers that are generated by the rebuilding
of terms in Mul.flatten. Rather than check them at each step of
the way, just handle them once when done traversing the args.