3
$\begingroup$

MMA 14.0

Can somebody explain why the following evaluates to False:

MemberQ[1/y[x], y, Infinity]

False
$\endgroup$
3
  • 4
    $\begingroup$ Use MemberQ[1/y[x], y[_], Heads -> True] or MemberQ[1/y[x], y[_]] or MemberQ[1/y[x], _y]. $\endgroup$
    – Domen
    Commented May 13 at 11:25
  • $\begingroup$ Thank you for the workaround. $\endgroup$ Commented May 13 at 11:37
  • 1
    $\begingroup$ For this sort of test, I might use Not[FreeQ[expr, y]]. But it depends. It's not the same as @Domen's MemberQ[expr, _y]. Of course, they give the same result on expr = 1/y[x]. But not when expr = 1/y. So it depends on what is desired and what inputs are possible. $\endgroup$
    – Goofy
    Commented May 13 at 15:53

1 Answer 1

4
$\begingroup$

The FullFormof 1/y[x] is Power[y[x],-1]

Let's see what elements MemberQ say are present

# -> MemberQ[1/y[x], #, Infinity] & /@ {x, y, 1, -1, Power} 
{x->True,y->False,1->False,-1->True,Power->False}

Both Power and y are not elements, but Heads

As pointed out by @Domen, using the option Heads -> True will include the Heads in the search

enter image description here

# -> MemberQ[1/y[x], #, Infinity, Heads -> True] & /@ {x, y, 1, -1, 
  Power} 
{x->True,y->True,1->False,-1->True,Power->True} 
$\endgroup$
1
  • 1
    $\begingroup$ Thanks a lot for pointing out that this is a question of "Head" $\endgroup$ Commented May 13 at 16:12

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