Re: pattern matching against the Dt function?
- To: mathgroup at smc.vnet.net
- Subject: [mg85276] Re: pattern matching against the Dt function?
- From: Grischika at mail.ru
- Date: Tue, 5 Feb 2008 06:01:38 -0500 (EST)
- References: <fo6h46$r20$1@smc.vnet.net>
On 4 =C6=C5=D7, 10:07, "Adam M." <ad... at san.rr.com> wrote:
> Hello,
>
> I'm having trouble matching the Dt function with a pattern, even though
> it works for all other functions I've tried.
>
> (*It doesn't match Dt[b] here.*)
> In[101]:= {f[a], Dt[b]} /. Dt[n_]->n
> Out[101]= {f[a], Dt[b]}
>......
>.....
>
> I've read every section on pattern matching in the documentation center,
> and I'm at a complete loss to explain why I can't seem to match the Dt
> function with the Dt[n_] pattern when I can match these other functions.
> I know I can use the _Dt pattern to match it, but then I don't get
> control over matching the arguments...
>
> Thank you.
>
> Very curious,
> -- Adam M.
Instead of using Hold on lefthand side of Replace you should use
HoldPattern on right as follows:
> In[101]:= {f[a], Dt[b]} /. HoldPattern[Dt[n_]]->n
> Out[101]= {f[a], Dt[b]}
To understand were the problem is try to evaluate Dt[n_].
Or next example:
In[]:= HoldForm[Expand[(a+b)^3]]/.{Expand[x_]->x}
Out[]:=Expand[(a+b)^3]
and
In[]:= HoldForm[Expand[(a+b)^3]]/.{HoldPattern[Expand[x_]]->x}
Out[]:=(a+b)^3