Re: Integer designation
- To: mathgroup@smc.vnet.net
- Subject: [mg11795] Re: Integer designation
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Sat, 28 Mar 1998 00:25:31 -0500
- References: <6fd5fr$6b7@smc.vnet.net>
blimbaum_jerry@ccmail.ncsc.navy.mil wrote: > On page 261 of the 3rd edition of > Mathematica > it talks about making an integer assignment, i.e. "f[n_Integer] is > like defining a function f that must take an argument of "type" > Integer. I try this in a function like f[x_,n_Integer]:=Sin[n Pi > (x/a)] and then type f[a,n] and expect the answer zero but it just > gives me Sin[n Pi]. What have I misunderstood here? > > thanks. Jerry Blimbaum US Navy Lab, Panama City, Florida Jerry: In[2]:= f[x_,n_Integer]:=Sin[n Pi (x/a)] Means: "change f[x,n] to Sin[ n Pi (x/a)] if and only if n is an integer (has head Integer)" In[3]:= f[x,2/3] Out[3]= 2 f[x, -] 3 In[4]:= f[x, 5] Out[4]= 5 Pi x Sin[------] 2 This will give zero iff x is an even integer. x_ is a form with name x that is matched by any expression n_Integer is a form with name n that is matched by any expression with head Integer (it does not mean that n *is* an integer). It ia usefull to see the full form of expressions when trying to understand behaviour. In[5]:= FullForm[x_] Out[5]//FullForm= Pattern[x, Blank[]] In[7]:= FullForm[n_Integer] Out[7]//FullForm= Pattern[n, Blank[Integer]] -- Allan Hayes Mathematica Training and Consulting Leicester, UK hay@haystack.demon.co.uk http://www.haystack.demon.co.uk voice: +44 (0)116 271 4198 fax: +44 (0)116 271 8642