4
$\begingroup$

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).

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

1 Answer 1

6
$\begingroup$

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:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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