Re: How do I tell Mathematica than n is an integer?
- To: mathgroup at smc.vnet.net
- Subject: [mg9614] Re: How do I tell Mathematica than n is an integer?
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Fri, 14 Nov 1997 21:39:55 -0500
- Organization: University of Western Australia
- Sender: owner-wri-mathgroup at wolfram.com
michael a. morrison wrote: > How do you tell Mathematica within a notebook session that a variable n > is a positive integer in such a way that a command defined in a package > such as > waveFunction[n_Integer?Positive] := will execute rather than > returning waveFunction[n] unevaluated. Setting > Integer[n] ^= True; > Postive[n] ^= True; > in the notebook has no effect whatsoever on the failure of Mathematica > to evaluate waveFunction[n]. > The assignment In[1]:= waveFunction[n_Integer?Positive]:=what checks the Head of n In[2]:= Head[n] Out[2]= Symbol which has to be an Integer, and then applies the Positive test. What you want to do, I think, is In[3]:= IntegerQ[n] ^= True; In[4]:= Positive[n] ^= True; In[5]:= ?n "Global`n" IntegerQ[n] ^= True Positive[n] ^= True then define a test for symbols with assigned properties: In[6]:= test[n_] := IntegerQ[n] && Positive[n] In[7]:= test[n] Out[7]= True Your function then reads In[8]:= waveFunction[n_?test] := blah In[9]:= waveFunction[n] Out[9]= blah In[10]:= waveFunction[m] Out[10]= waveFunction[m] Cheers, Paul ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul at physics.uwa.edu.au AUSTRALIA http://www.pd.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________