Re: How do I tell Mathematica than n is an integer?
- To: mathgroup at smc.vnet.net
- Subject: [mg9595] Re: [mg9583] How do I tell Mathematica than n is an integer?
- From: jpk at max.mpae.gwdg.de
- Date: Thu, 13 Nov 1997 23:24:06 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Hi Michael > 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 This will not work because n_Integer ask Head[n]===Integer. For Your symbolic n this will never be true. The head of "n" remains a symbol regardles what You say with Your definitions > 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 correct way to define the symbol "n" is a positive integer is n /: IntegerQ[n]:=True n /: Positive[n]:=True Your waveFunction[] must ask IntegerQ[n] and not Head[n]==Integer so the definition is waveFunction[n_ /; IntegerQ[n] && Positive[n]]:=Psi[n,x] Hope that helps Jens