Skip to content

FreeQ ​

Whether pattern matches nowhere in expr — itself, or any subexpression, at any depth.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageFreeQ✓
FreeQ(expr, pattern)True unless pattern matches expr or some subexpression
Typed signatures
TypePackageApplies
(any, any) -> booleancombinatoricsalways

Domain: Collections

Details
  • Searches the WHOLE tree, not just the top level — that's the difference from MatchQ, which only checks expr itself.
  • An Association's keys are not parts: only its values are searched.
  • Uses the same wildcard grammar as MatchQ — see its reference entry for what's supported.

Examples

Basic #
live ↗
InFreeQ(x2+1,x)\mathrm{FreeQ}(x^2+1, x)OutFalse\mathrm{False}

The pattern 00 occurs in the list, so it is not free of it

live ↗
InFreeQ([1,2,4,1,0],0)\mathrm{FreeQ}(\bigl\lbrack1, 2, 4, 1, 0\bigr\rbrack, 0)OutFalse\mathrm{False}

The search descends into sublists and finds the 00

live ↗
InFreeQ([[1,1,3,0],[2,1,2,2]],0)\mathrm{FreeQ}(\bigl\lbrack\bigl\lbrack1, 1, 3, 0\bigr\rbrack, \bigl\lbrack2, 1, 2, 2\bigr\rbrack\bigr\rbrack, 0)OutFalse\mathrm{False}

Values inside an association count as parts, so 11 is found

live ↗
InFreeQ(Association(KeyValuePair⁡(a,1)),1)\mathrm{FreeQ}(\mathrm{Association}(\operatorname{KeyValuePair}(a, 1)), 1)OutFalse\mathrm{False}
live ↗
InFreeQ(Association(Rule(a,1)),a)\mathrm{FreeQ}(\mathrm{Association}(\mathrm{Rule}(a, 1)), a)OutTrue\mathrm{True}
Scope #
live ↗
InFreeQ(x2+1,y)\mathrm{FreeQ}(x^2+1, y)OutTrue\mathrm{True}

b is found two levels deep

live ↗
InFreeQ([[a,b]],b)\mathrm{FreeQ}(\bigl\lbrack\bigl\lbrack a, b\bigr\rbrack\bigr\rbrack, b)OutFalse\mathrm{False}
About
Examples7
Checked againstWolfram Language 7 agree
CrosswalkWolfram Language

See also: MatchQ, Level