# \_?NumberQ for list arguments

**URL:** <https://community.wolfram.com/t/numberq-for-list-arguments/1240>\
**Category:** Ideas\
**Tags:** software-development, mathematica\
**Created:** [January 9, 2014, 2:39pm UTC](https://community.wolfram.com/t/numberq-for-list-arguments/1240 "2014-01-09T14:39:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [January 9, 2014, 2:39pm UTC](https://community.wolfram.com/t/numberq-for-list-arguments/1240/1 "2014-01-09T14:39:27Z")

</div>

Yesterday I wanted to run NMinimize on a numeric function with 21 arguments and didn’t want to put \_?NumberQ after each argument.  
I decided it was time to figure out an equivalent approach for list arguments, since the documentation doesn’t tell how to do that (as far as I know).  
Here’s an example of what I came up with:

```auto
f[l_List /; And @@ (NumberQ /@ l)] := l.l

```

And here are tests showing that it only evaluates for a list with all numeric components:

```auto
f[Range[5]]

```

```auto
55

```

```auto
f[{3, a}]

```

```auto
f[{3, a}]

```

Some of you may be wondering why this is useful. Some numeric functions, such as FindMinimum and NMinimize,  
first evaluate their arguments symbolically, probably to get symbolic derivatives, etc. However, if an  
argument is a user-defined function that fails for symbolic arguments, FindMinimum and NMinimize will fail.  
The documentation says to put \_?NumberQ after the scalar numeric function arguments so that symbolic evaluation  
will return unevaluated and the algorithm will know that the function is numeric. As I said earlier, I haven’t seen an  
equivalent approach for list arguments so I came up with my own.

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [January 9, 2014, 2:55pm UTC](https://community.wolfram.com/t/numberq-for-list-arguments/1240/2 "2014-01-09T14:55:30Z")

</div>

I usually end up using [VectorQ](http://reference.wolfram.com/mathematica/ref/VectorQ.html) in this case alongside NumericQ like this:

```auto
f[x_?(VectorQ[#, NumericQ] &)]:=

```

It’s not actually much more elegant or readable, but it’s there.

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [January 9, 2014, 3:23pm UTC](https://community.wolfram.com/t/numberq-for-list-arguments/1240/3 "2014-01-09T15:23:13Z")

</div>

A nice application of VectorQ[expr, test]
