In finding an answer to my other question, I'm finding myself needing to manipulate the conditions imposed on replacement rules, but this is proving to be a little difficult. In particular, how should I go about removing instances of Condition
and PatternTest
?
Using the code from my other answer (slightly adjusted):
f[x_?InexactNumberQ] := x^2;
g[x_] /; FooQ[x] := x^3;
Attributes[ExpandValues] = {HoldAll};
ExpandValues[symbol_] := Join @@ Through[
{OwnValues, DownValues, UpValues, SubValues, DefaultValues, NValues}[symbol]
];
ExpandValues[symbol_, symbols__] := Join[ExpandValues[symbol], ExpandValues[symbols]];
then the replacement rules that need to be modified are:
{
HoldPattern[f[(x_)?InexactNumberQ]] :> x^2,
HoldPattern[g[x_] /; FooQ[x]] :> x^3
}
I would like these to be modified to not have any conditions on the arguments, but trying to replace the condition and pattern test is proving difficult. This for example does not work:
{
HoldPattern[Condition[p_, q_]] :> p,
HoldPattern[PatternTest[p_, q_]] :> p
}
I've also tried using Verbatim
which the documentation suggests is useful to transform other transformation rules, but I have not gotten them to work. I'm also thinking that the use of Verbatim won't work generally because it is too literal.
I've had partial success with
{
Condition -> (#1 &),
PatternTest -> (#1 &)
}
but when the replacement appears within a HoldPattern
, the resulting rule after replacement does not work.
{HoldPattern[f[(x_)?InexactNumberQ]] :> x^2, HoldPattern[g[x_] /; FooQ[x]] :> x^3} /. (Condition | PatternTest)[ p_, q_] :> p
works. $\endgroup$