MathGroup Archive 2008

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

Search the Archive

Re: simple pattern match question


On Aug 7, 2008, at 4:42 AM, congruentialuminaire at yahoo.com wrote:

> Hello UG:
>
> I am trying to understand simple pattern rule evaulation. The
> following trivial examples baffles me:
>
> ---------------------------------------------------
> In[1]:= f[x_Number] := x ^ 2
> In[2]:= f[3]
> Out[2]= f[3]
>
> In[3]:= f[3.3]
> Out[3]= f[3.3]
>
> In[4]:= NumberQ[3.3]
> Out[4]= True
> --------------------------------------------------
> Why is it that f[3.3] does not evaluate??

for the same reason f[3] does not evaluate, the pattern _Number  
matches expressions whose head is Number, the head of 3 is Integer  
the head of 3.3 is Real, neither match.  If you want f to only  
evaluate for real values define it as f[x_Real].

Regards,

Ssezi


  • Prev by Date: Re: simple pattern match question
  • Next by Date: Re: Multiplying a vector over multiple vectors
  • Previous by thread: Re: simple pattern match question
  • Next by thread: Re: simple pattern match question