checking for state of variables when assigned to by foldable ops

Some functions also moved from constant_propagation to util as also used
in condtional_constant_propagation