MathGroup Archive 1997

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

Search the Archive

Re: How do I tell Mathematica than n is an integer?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9620] Re: [mg9583] How do I tell Mathematica than n is an integer?
  • From: seanross at worldnet.att.net
  • Date: Fri, 14 Nov 1997 21:40:00 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

michael a. morrison wrote:
> 
> In writing some packages for courses I'm teaching, I've run into the
> following recurrent difficulty:
> 
> 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].
> 
> I would be very grateful for any advice anyone can give me!
> Thanks---michael morrison (university of oklahoma)
> 
> Michael A. Morrison
> Dept. Physics & Astronomy
> University of Oklahoma
> Norman, OK 73019
> Phone: 405 325-3961
> FAX: 405 325-7557

If I understand correctly, you want to execute the function symbolically
without specifying an actual value for n, but just tell Mathematica
that n is a positive integer.  The problem is that Mathematica has no
declaration or typing beyond the Head.  There is no Head for positive
integer.  As far as I know, there is no direct way to do what you want.
Several of us have lamented the absense of true object oriented
variable typing, but the Wolfram gurus have told us, and I believe
them, that it is a devilishly difficult thing to do in general.

 If you get rid of the test on your symbol n and execute the function,
doesn't that return the answer you want?  Another thing you could do is
to force the value of n to be a positive integer inside your code by
use of Round and Abs.
-- 
Remove the _nospam_ in the return address to respond.


  • Prev by Date: Montecarlo Markov Chain
  • Next by Date: Help, Help, Help.
  • Previous by thread: Re: How do I tell Mathematica than n is an integer?
  • Next by thread: Re: How do I tell Mathematica than n is an integer?