Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 6 down vote accepted

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[].

share|improve this answer
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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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