This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Built-in Functions / Programming / Tests  /
FreeQ

  • FreeQ[ expr , form ] yields True if no subexpression in expr matches form, and yields False otherwise.
  • FreeQ[ expr , form , levelspec ] tests only those parts of expr on levels specified by levelspec.
  • form can be a pattern.
  • Example: FreeQ[f[x^2] + y^2, x^_].
  • FreeQ looks at the heads of raw expressions, testing whether those heads match form.
  • See the Mathematica book: Section 1.8.5, Section 2.1.5Section 2.3.5.
  • See also: MemberQ, Count.

    Further Examples

    (See also the Further Examples for the Heads option.)
    This example shows a feature of FreeQ that is absent from MemberQ: here, FreeQ recognizes that the sum a+c is a subexpression of the larger sum.

    In[1]:=

    Out[1]=

    Here we see how the level argument to FreeQ affects its result. When no level is specified, matches at any level are reported.

    In[2]:=

    Out[2]=

    In[3]:=

    Out[3]=

    In[4]:=

    Out[4]=

    In[5]:=

    Out[5]=