5

Mr.Wizard's question about MemberQ and FreeQ got me to re-read the documentation for those functions. I find I don't understand the 3rd bullet point made under Details and Options of MemberQ.

MemberQ[list, form] immediately tests whether any expression in list matches form; Element[x, dom] asserts that x is an element of the symbolic domain dom.

Can someone explain what point is being made here? The text after the semicolon reads as a non sequitur to me.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257

2 Answers2

6

Yes, this statement looks almost as if the last part is just a repetition of the first part with different wording, but for a different command. But there is an important difference, ad the juxtaposition of the two commands MemberQ and Element is probably intended to highlight that difference:

It's all in the word immediate. The difference is probably best illustrated by example:

Element[f[x], Reals]

(* ==> f[x] ∈ Reals *)

MemberQ[{1, 2}, f[x]]

(* ==> False *)

In the case of Element, the expression remained unevaluated because f[x] wasn't defined so we can't decide whether it's real. However, MemberQ is not that patient. It gives False because at that immediate instant of evaluation, f[x] is explicitly of Head f and therefore doesn't explicitly belong to the list given.

So my interpretation is that the statement in the documentation is intended to point out this distinction between MemberQ and Element.

Jens
  • 97,245
  • 7
  • 213
  • 499
  • You may be right, but I'm not convinced. To me there is no context in this sentence to establish any relation at all between MemberQ and Element. And, since the sentence stands alone, no other context to establish a relationship, either. – m_goldberg Oct 09 '14 at 05:07
  • I'm going by my knowledge of what all the other functions ending in Q also do. They differ from tests such as Element in that they assign a truth value based on the immediate, explicit structure of the argument. Think of TrueQ: it's very quick to give False because it only gives you True if you give it True first. In other words, functions ending in Q don't ever give "maybe" as an answer... – Jens Oct 09 '14 at 05:19
6

As far as I can tell, this wording was introduced in the V4 documentation. It predates the current documentation conventions where relationships and contrasts between functions are usually noted under the Properties & Relations heading. So I think that the wording is simply there to guide the user to the Element function if the goal is to do domain-testing instead of testing list membership.

The two concepts are very similar if not identical in mathematical writing: "i being a member of the set of integers", "i being an element of {1, 2, 3, 4}". Mathematica artificially distinguishes the operations for practical reasons, and the documentation is pointing this out.

WReach
  • 68,832
  • 4
  • 164
  • 269
  • That historical explanation of why they put the wording in the front section seems to make sense (+1). – Jens Oct 09 '14 at 16:19