MathGroup Archive 1996

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

Search the Archive

Re: Argument types

From: Olivier Georg <olivier.georg at>
To: mathgroup at
Subject: [mg5345] Argument types

> I recently discovered that you could specify the type of the
> arguments of a function being defined.  For example, f[x_Integer]
> if you want x to be an integer.  There's also List, Real, Complex
> and Symbol.  But there's also ?MatrixQ which is not in the
> Mathematica book, to specify a matrix.  Are there other types?


_h is matched by anything with head h; this can be explicit for  
example h[], h[1],h[1,2,3].
Unfortunately, you can't see 3 in the form Integer[3], but you can  
find its head formally:

In[1]:= Head[3]
Out[1]= Integer

The following tests always give True or False

AtomQ        DigitQ            EvenQ         FreeQ
IntegerQ     IntervalMemberQ   LetterQ       ListQ
LowerCaseQ   MachineNumberQ    MatchQ        MatrixQ
MemberQ      NameQ             NumberQ       OddQ
OptionQ      OrderedQ          PolynomialQ   PrimeQ
SameQ        StringMatchQ      StringQ       SyntaxQ
TrueQ        UnsameQ           UpperCaseQ    ValueQ

Then there are tests that remain unevaluated when the question  
cannot be decided on the information available:

Equal         Unequal        Less       Greater
LessEqual     GreaterEqual   Positive   Negative

For example

In[2]:= Positive[a]
Out[2]= Positive[a]

However, you can always arrange that the output is always True or  
False by using TrueQ:

In[3]:= TrueQ[Positive[a]]
Out[3]= False

You can sometimes combine these:
For example test if the entries in a matrix are all numbers:

In[4]:= MatrixQ[{{1},{2}},NumberQ]
Out[4]= True

In[5]:= MatrixQ[{{1},{a}},NumberQ]
Out[5] = False

Allan Hayes
hay at

  • Prev by Date: Mathematica etc.
  • Next by Date: Re: 3D data plot
  • Previous by thread: Re: Re: Mathematica etc.
  • Next by thread: Re: Argument types