I have a named expression: expr := a + b
. a
and b
are also named expressions.
Let's say a := x + y
, b := z + w
. This means that expr becomes x + y + z + w
At this point I want to replace Plus
to Times
in expr
(but only in expr
) to get (x+y)*(z+w)
.
Can this be done?
Additional info: I have no control over how any of the expressions are defined. Ultimately this boils down to:
a := x + y
expr := a + b
b := z + w
(* I have no control over the code above. The order is not defined. *)
magic[expr, Plus -> Times]
(* (x + y) (w + z) *)
Is magic
possible to implement?