       Re: simple pattern match question

• To: mathgroup at smc.vnet.net
• Subject: [mg91181] Re: simple pattern match question
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Fri, 8 Aug 2008 07:16:48 -0400 (EDT)

```On 8/7/08 at 4:42 AM, congruentialuminaire at yahoo.com wrote:

>I am trying to understand simple pattern rule evaulation. The
>following trivial examples baffles me:

>---------------------------------------------------
>In:= f[x_Number] := x ^ 2
>In:= f
>Out= f

>In:= f[3.3]
>Out= f[3.3]

>In:= NumberQ[3.3]
>Out= True
>--------------------------------------------------
>Why is it that f[3.3] does not evaluate??

Because there is no built-in object with Head of Number. That is:

Out= Real

So,

In:= f[x_Real] := x^2
f[3.3]

Out= 10.89

But then

In:= f

Out= f(3)

Since,

Out= Integer

So, you might want to use something more general such as

In:= g[x_?NumericQ] := x^2
g[3.3]
g

Out= 10.89

Out= 9

```

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