# Using FreeQ with implicit functions

In Mathematica 7, I want to determine whether a list of free of numbers greater than 1 or not. It seems like using FreeQ would be a concise way to do this:

FreeQ[{2, 1}, # > 1 &] (* The output is: True *)

FreeQ[{1, 1}, # > 1 &] (* The output is: True *)


Why does FreeQ[{2, 1}, # > 1 &] give True? {2, 1} is not free of numbers greater than 1, so I must be using FreeQ incorrectly.

FreeQ[] expects an object or a pattern as its second argument, as opposed to a Boolean function. What you should be doing is FreeQ[{2, 1}, _?(# > 1 &)]. Yes, the parentheses are needed.

A similar statement applies to the other pattern-matching functions of Mathematica, e.g. Cases[], Position[], and MatchQ[].

• Ah, I made a silly mistake! Thank you for being patient and gentle with me. – Andrew May 19 '12 at 18:21

Supporting J.M.'s answer you could also use Condition rather than PatternTest:

FreeQ[{2, 1}, x_ /; x > 1]


This is usually slightly faster. Faster still in many cases is Max, assuming numeric data:

Max[{2, 1}] <= 1