FreeQ
Details and Options
- form can be a pattern.
- FreeQ uses standard level specifications:
-
n levels 1 through n Infinity levels 1 through Infinity {n} level n only {n1,n2} levels n1 through n2 - The default value for levelspec in FreeQ is {0, Infinity}.
- A positive level n consists of all parts of expr specified by n indices.
- A negative level -n consists of all parts of expr with depth n.
- Level -1 consists of numbers, symbols and other objects that do not have subparts.
- Level 0 corresponds to the whole expression.
- With the default option setting Heads->True, FreeQ looks at heads of expressions, and their parts.
- FreeQ works on associations, testing values but not keys.
- FreeQ[form][expr] is equivalent to FreeQ[expr,form].
- Parallelize[FreeQ[expr,form]] computes FreeQ[expr,form] in parallel on all subkernels. »
Examples
open all close allBasic Examples (3)
Test whether a list is free of 0:
FreeQ[{1, 2, 4, 1, 0}, 0]FreeQ normally tests all levels in an expression:
FreeQ[{{1, 1, 3, 0}, {2, 1, 2, 2}}, 0]Test whether an association does not contain a value:
FreeQ[<|a -> 1|>, 1]FreeQ[<|a -> 1|>, a]Scope (5)
FreeQ works with patterns:
FreeQ[{a, b, b, a, a, a}, _Integer]FreeQ[{x ^ 2, y ^ 3, x ^ 5, x ^ 6}, y ^ _]Use Verbatim to test for a literal blank:
FreeQ[f[_], Verbatim[_]]Test whether an association contains a specific rule:
FreeQ[<|a -> 1|>, KeyValuePattern[{a -> 1}]]FreeQ[<|a -> 1|>, KeyValuePattern[{b -> 1}]]Test whether a list of rules contains a specific rule:
FreeQ[{a -> 1}, KeyValuePattern[{a -> 1}]]Test whether an association contains a specific key:
FreeQ[<|a -> b|>, KeyValuePattern[{a -> _}]]Applications (2)
Properties & Relations (1)
Compute FreeQ in parallel:
Parallelize[FreeQ[Range[10 ^ 6], 5]]Possible Issues (2)
For associations, FreeQ tests only values:
FreeQ[<|a -> 1|>, 1]FreeQ[<|a -> 1|>, a]KeyValuePattern tests for the entire rule:
FreeQ[<|a -> 1|>, KeyValuePattern[{a -> _}]]FreeQ[<|a -> 1|>, KeyValuePattern[{b -> _}]]Related Guides
History
Introduced in 1988 (1.0) | Updated in 2014 (10.0)
Text
Wolfram Research (1988), FreeQ, Wolfram Language function, https://reference.wolfram.com/language/ref/FreeQ.html (updated 2014).
CMS
Wolfram Language. 1988. "FreeQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/FreeQ.html.
APA
Wolfram Language. (1988). FreeQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FreeQ.html
BibTeX
@misc{reference.wolfram_2026_freeq, author="Wolfram Research", title="{FreeQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/FreeQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_freeq, organization={Wolfram Research}, title={FreeQ}, year={2014}, url={https://reference.wolfram.com/language/ref/FreeQ.html}, note=[Accessed: 13-June-2026]}