I have a simple expression containing a Condition(s) like
a /; a > 1 I wish to separate the expression from the condition, to display like
| expr | cond | ---------------- | a | a > 1 | How can I obtain the sub-expression a from the expression a /; a > 1? Attempting to remove the Conditions by Replace doesn't seem to work, probably because the Condition in the pattern is being interpreted at the top-level:
in = a /; a > 1 in /. Condition[expr_, cond_] :> expr in /. HoldPattern[Condition[expr_, cond_]] :> expr in /. Unevaluated[Condition[expr_, cond_]] :> expr in /. Verbatim[Condition[expr_, cond_]] :> expr These all output the unchanged input:
>>> a /; a > 1 Here's a hacky workaround:
in /. Condition -> dummy /. dummy[expr_,cond_] :> expr What's the right way to do this?
in /. Verbatim[Condition][expr_, cond_] :> expr? $\endgroup$in /. HoldPattern[Condition][expr_, cond_] :> expr$\endgroup$in /. Condition -> (# &)andin /. c_Condition :> First[c]$\endgroup$HoldPattern[Condition][expr_, cond_]- I think this is a misuse ofHoldPattern, which is used whereVerbatimshould be used. $\endgroup$