4

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, _, _]]
(*False*)

as it should be, but

FreeQ[Hypergeometric2F1[a1, a2, b1, x], Hypergeometric2F1[_, _, _, _]]
(*True*)

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

Eckhard
  • 1,395
  • 9
  • 17

1 Answers1

6

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

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

2 _

_^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][_, _, _, _]]
False

False

Recommended reading:

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371