MathGroup Archive 2008

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

Search the Archive

Re: simple pattern match question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91186] Re: simple pattern match question
  • From: amzoti <amzoti at gmail.com>
  • Date: Fri, 8 Aug 2008 07:17:43 -0400 (EDT)
  • References: <g7ed78$2po$1@smc.vnet.net>

On Aug 7, 1:54 am, congruentialumina... 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??
>
> TIA.
>
> Regards..RogerW

Didn't you want the following?

f[x_?NumberQ] := x^2

f[3] = 9

f[3.3] = 10.89

f[p] = f[p]

You could also do thing like

f[x_?IntegerQ] := x^2

f[3] = 9

f[3.3] = f[3.3]

Hope I understood your original question correctly .

~W


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