Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can the Element[] function only be used for the domains given in the documentation? I am trying to use it to determine if a value is contained in a previously defined list. Thanks!

share|improve this question
It only works for domains, yes. You might be interested in MemberQ[]... – J. M. May 28 '13 at 14:00
Thanks. That should do the trick – yankeefan11 May 28 '13 at 14:03
You should be able to answer your own question, now... – J. M. May 28 '13 at 14:04
There is an exception to J.M.'s answer: upvalues, although it would only be shorthand for MemberQ[]. – rcollyer May 28 '13 at 14:06
Difference is also that Element is a kind of assertion, you tell Mathematica that a given variable belongs to a given domain, whereas MemberQ is a test; you ask Mathematica whether a value is member of a list. – Sjoerd C. de Vries May 28 '13 at 20:26

There are as usual several ways. The most convenient one is probably MemberQ, as already pointed out in the comments.

MemberQ[{1, 2, 3, 4, 9}, 9]
(* True *)

If you have a complex structure and not only a flat list, then FreeQ can be of use. Note that you have to negate the result.

MemberQ[{1, 2, {3}, {{4, 9}}}, 9]
Not[FreeQ[{1, 2, {3}, {{4, 9}}}, 9]]
(* False *)
(* True *)

Finally, note that you can specify the level where MemberQ should look for the appearance of the element

MemberQ[{1, 2, {3}, {{4, 9}}}, 9, Infinity]
(* True *)
share|improve this answer

I have not tested it, but this dirty hack might be pretty fast IF you have to assess membership in a list of symbolic values with no zeros.

symMemberQ[x_, mylist_] := SameQ[Times @@ Flatten[mylist /. x -> 0], 0]

Adding Flatten wil take care of nested list.

symMemberQ[e, {a, {b, g}, {d, {e, f}}}]
symMemberQ[w, {a, {b, g}, {d, {e, f}}}]

(It's a dirty hack, so beware: it might bite you).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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