MathGroup Archive 2008

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

Search the Archive

Re: simple pattern match question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91174] Re: [mg91151] simple pattern match question
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Fri, 8 Aug 2008 07:15:27 -0400 (EDT)
  • References: <200808070842.EAA02148@smc.vnet.net>

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