MathGroup Archive 1998

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

Search the Archive

Re: Integer designation



blimbaum_jerry@ccmail.ncsc.navy.mil wrote:
> 
>      I want to re-ask a question I asked before about designating a
>      variable as an integer.  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
> 
> 
>                 Long Live MathGroup

f[x_Integer] merely says that this function is only defined if x is an
integer.  If you insert a real number for that argument, there is no
definition.  There is no "data typing" in mathematica.  As far as I
know, there is absolutely no way to tell mathematica that a certain
symbol is an integer of unspecified value.  The only function that has
some of this kind of functionality in it is Integrate which has an
Assumptions option.

Also,

f[x_,n_Integer]:=Sin[n Pi(x/a)]
f[a,n]

should have returned

f[a,n]

not

Sin[n Pi]

I suspect that there were other definitions operating in your session,
perhaps from previous versions of the symbol f.  In general, it is good
programming practice to Clear the definition of a symbol before every
function definition, as in:

Clear[f]
f[x_,n_Integer]:=Sin[n Pi(x/a)]
f[a,n]


Remember that mathematica loads definitions and rules into the kernel in
the order of execution from the start of the session to the end.  You
can delete every cell in the notebook or even close the notebook and
start a new one and you have not affected the definitions in the kernel
one bit.  If you enter a definition for f[x_,n_], that does not affect
previous definitions for f[x_Real,n_Complex], f[x_,n_Integer] etc. 
They all exist simultaneously.

-- 
Remove the _nospam_ in the return address to respond.



  • Prev by Date: Re: Vectors and Mathematica
  • Next by Date: Re: RE: Re: odd behavior of NDSolv
  • Prev by thread: Integer designation
  • Next by thread: Re: Integer designation