Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: [mg5345] Argument types
Posted:
Dec 1, 1996 11:25 PM


From: Olivier Georg <olivier.georg@studi.epfl.ch> 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?
Olivier,
_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 NonNegative
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@haystack.demon.co.uk http://www.haystack.demon.co.uk



