I'm trying to figure out if a calculation result it's a valid result. As it return a matrix, I need to test that every element it's a number, so I thought this could work...

numericTable = Range[12] ~Partition ~ 4;
check=( NumberQ/@Flatten@numericTable) /.List->Sequence ;

This should return True or False depending if exist or not a non-numerical element in the matrix. But it returns


So I don't understand anything, because...

In[]:= Sequence[True,True,True,True,True,True,True,True,True,True,True,True]===check
Out[]= True
Out[]= True

Where's the catch ???

  • 1
    $\begingroup$ Why not just And @@ (NumberQ /@ Flatten@numericTable)? $\endgroup$ Feb 21, 2013 at 16:41
  • $\begingroup$ Or a combination of MatrixQ and NumberQ as in the docs ? $\endgroup$ Feb 21, 2013 at 16:42
  • $\begingroup$ @PinguinDirk you're right... in fact I found some code where I did that, but still I would like to understand where's the problem with Sequence... $\endgroup$
    – crazzymath
    Feb 21, 2013 at 16:44
  • 1
    $\begingroup$ @belisarius - thanks for the example - I will post an answer - feel free to edit that later. thanks $\endgroup$ Feb 21, 2013 at 17:02
  • 1
    $\begingroup$ Duplicate: mathematica.stackexchange.com/q/16694/5 $\endgroup$
    – rm -rf
    Feb 21, 2013 at 17:09

2 Answers 2


As in the comments above, we see that the HoldAll attribute is causing the "problem".

Note that if we unset HoldAll it works:

ClearAttributes[And, HoldAll];




EDIT: based on Oleksandr R.'s comment, I must stress that I showed this only to illustrate the "problem". It is not a good idea to unset HoldAll for And, as noted below in his comment. So as in my comment to the question above, you can just use Evaluate to get the result:


to get to the same result.


You could directly apply And on what you constructed:

And @@ (NumberQ /@ Flatten@numericTable)

but better check MrWizard's answer for a direct solution of your problem.

  • $\begingroup$ Well done! :) .. $\endgroup$ Feb 21, 2013 at 17:31
  • $\begingroup$ & thanks for your input! $\endgroup$ Feb 21, 2013 at 17:45
  • 2
    $\begingroup$ Removing HoldAll is a very bad idea in the case of And: it destroys the short-cut evaluation semantics, which are frequently relied upon for correctness. If you know you don't need this in a particular situation, a better way is to apply Evaluate for that case only or inject the evaluated argument using With. I'm downvoting for now due to this, but will remove it when you update your answer to override HoldAll more "correctly". $\endgroup$ Feb 21, 2013 at 21:06
  • $\begingroup$ @OleksandrR.: it was meant to illustrate the point, but thanks for pointing it out that it is misleading - I will edit my post accordingly. Thanks for the input! $\endgroup$ Feb 21, 2013 at 21:23
  • $\begingroup$ Earned the +1 after your edit $\endgroup$
    – Rojo
    Feb 21, 2013 at 21:29

In addition to HoldAll as highlighted by Pinguin Dirk the other component of the behavior is that And directly returns single arguments:


Combined, And[check] spits out check which at the top level evaluates to Sequence[True, . . .].

One problem with your method for checking the matrix is that it does not short-circuit on a non-numeric value, and therefore it may waste time. That is, NumberQ is applied to every element even if the very first one is non-numeric. A faster approach is to use the built-in MatrixQ:

MatrixQ[numericTable, NumberQ]
  • $\begingroup$ I accept the @PinguinDirk response because I only accept just one and he was first, but thank you for your response (and other responses all over the MSE, I'm a fan ;-) $\endgroup$
    – crazzymath
    Feb 25, 2013 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.