MathGroup Archive 2008

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

Search the Archive

Re: simple pattern match question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91177] Re: [mg91151] simple pattern match question
  • From: "Adriano Pascoletti" <adriano.pascoletti at gmail.com>
  • Date: Fri, 8 Aug 2008 07:16:00 -0400 (EDT)
  • References: <200808070842.EAA02148@smc.vnet.net>

Roger,

the Mathematica help says that "Number represents an exact integer or
an approximate real number in Read". Use NumericQ:

In[1]:= f[(x_)?NumericQ] := x^2

In[2]:= f[3]

Out[2]= 9

In[3]:= f[3.3]

Out[3]= 10.889999999999999

If you are tempted to use NumberQ  note that

In[4]:= NumberQ[Pi]

Out[4]= False

In[5]:= NumericQ[Pi]

Out[5]= True

Adriano Pascoletti

2008/8/7 <congruentialuminaire at yahoo.com>
>
> 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??
>
> TIA.
>
> Regards..RogerW
>


  • Prev by Date: Re: simple pattern match question
  • Next by Date: Re: simple pattern match question
  • Previous by thread: simple pattern match question
  • Next by thread: Re: simple pattern match question