How might I remove Removed[..]
symbols from the output of an expression?
For example
Clear[b]; b := Sin[a + a]; Remove[a];
b
Sin[2 Removed[a]]
Now as discussed in the story of removed symbols, Removed[a]
aren't functions with Heads
but symbols with special forms.
This works for catching the symbols.
b /. Cases[b, s_Symbol :> (s :> a), {0, Infinity}, Heads -> True]
But how might I generalize this to all symbols?
Here is my evolving code. ToString[s] == Removed
should likely be generalized, but more importantly I can't seem to prevent s:>newHead
from going unevaluated.
Replace[b,
HoldPattern[s_Symbol] :>
With[{newHead = If[ToString[s] === "Removed[a]"
a, b
]},
s :> newHead /; True], Infinity
]