MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: pattern matching against the Dt function?

  • To: mathgroup at
  • Subject: [mg85275] Re: pattern matching against the Dt function?
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at>
  • Date: Tue, 5 Feb 2008 06:01:07 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fo6h46$r20$>

Adam M. 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]}
> (*But it matches f[a] with no problem.*)
> In[100]:= {f[a], Dt[b]} /. f[n_]->n
> Out[100]= {a, Dt[b]}
> (*In a process of elimination, I tried another built-in function, D, and 
> it worked fine.*)
> In[99]:= {f[a], D[b]} /. D[n_]->n
> Out[99]= {f[a], b}
> (*I tried another function more than one character long, Sin, and that 
> works.*)
> In[102]:= {f[a], Sin[b]} /. Sin[n_]->n
> Out[102]= {f[a], b}
> (*The full forms all seem to follow the same pattern.*)
> In[103]:= Sin[b] // FullForm
> Out[103]//FullForm= Sin[b]
> In[104]:= Dt[b] // FullForm
> Out[104]//FullForm= Dt[b]
> In[105]:= f[b] // FullForm
> Out[105]//FullForm= f[b]
> (*I thought it might be related to the evaluation of the Dt function, so 
> I tried Holding it. No luck.*)
> In[111]:= {f[a], Hold[Dt[b]]} /. Dt[n_]->n
> Out[111]= {f[a], Hold[Dt[b]]}
> (*However, it has no problem matching f[a] in a Hold.*)
> In[112]:= {Hold[f[a]], Dt[b]} /. f[n_]->n
> Out[112]= {Hold[a], Dt[b]}
> (*I tried looking at the attributes to find out if there was something 
> special about the Dt function, but it doesn't seem like it...*)
> In[116]:= Attributes[Sin]
> Out[116]= {Listable, NumericFunction, Protected}
> In[117]:= Attributes[D]
> Out[117]= {Protected, ReadProtected}
> In[118]:= Attributes[Dt]
> Out[118]= {Protected}
> 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.

Hi Adam,

For some reason the total derivative function Dt[n_] is expanding by the 
pattern matcher as the product of the symbol Dt by the first partial 
derivative of the pattern n_. No wonder that it cannot find Dt[b] after 
that! You can see the expansion by using either FullForm or Trace, as in 
the following example:

In[1]:= FullForm[Dt[n_]]

Out[1]//FullForm= Times[Dt[n], Derivative[1, 0][Pattern][n,


In[2]:= {f[a], Dt[b]} /. Dt[n_] -> n // Trace

{{{Dt[n_], Dt[n] Pattern     [n, _]},

    Dt[n] Pattern     [n, _] -> n,

    Dt[n] Pattern     [n, _] -> n},

   {f[a], Dt[b]} /.

    Dt[n] Pattern     [n, _] -> n,

   {f[a], Dt[b]}}

In[3]:= $Version

Out[3]= 6.0 for Mac OS X x86 (64-bit) (June 19, 2007)


  • Prev by Date: Re: pattern matching against the Dt function?
  • Next by Date: Re: pattern matching against the Dt function?
  • Previous by thread: Re: pattern matching against the Dt function?
  • Next by thread: Re: pattern matching against the Dt function?