I was trying to use FreeQ to test for the presence of Hypergeometric2F1 functions in my expressions. I encountered the following strange behaviour relating to the use of blanks _ as arguments of Hypergeometric2F1 in the pattern to be tested for.

FreeQ[Hypergeometric2F1[a1, a2, b1, x], Hypergeometric2F1[a1, a2, _, _]]

as it should be, but

FreeQ[Hypergeometric2F1[a1, a2, b1, x], Hypergeometric2F1[_, _, _, _]]

I'd be grateful if someone could educate me what's going on here. I use version 9.0 on Linux x86 (64-bit).

  • $\begingroup$ Related, perhaps duplicate: (27437) $\endgroup$ – Mr.Wizard Jul 29 '17 at 11:08

Whenever you run into unexpected results with pattern matching you need to consider how the pattern object itself evaluates. For example consider these:

Plus[_, _]
Times[_, _]

2 _


And now your pattern:

Hypergeometric2F1[_, _, _, _]
(1 - _)^-_

To prevent this evaluation you can use either HoldPattern or Verbatim:

FreeQ[Hypergeometric2F1[a1, a2, b1, x], HoldPattern @ Hypergeometric2F1[_, _, _, _]]

FreeQ[Hypergeometric2F1[a1, a2, b1, x], Verbatim[Hypergeometric2F1][_, _, _, _]]


Recommended reading:

  • $\begingroup$ Thanks, Mr.Wizard, also for the pointers to further reading! $\endgroup$ – Eckhard Oct 25 '14 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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