use `simultaneous=True` to delay evaluation in is_constant
use subs not xreplace during simultaneous replacement

xreplace will indiscriminately replace all occurances of
variables (even those in dummy positions) so subs is used
instead.