# Checking if an edge is an element of a list of edges

I have graph whose edge list is given by

edges = {1 \[UndirectedEdge] 1, 1 \[UndirectedEdge] 2, 1 \[UndirectedEdge] 3, 1 \[UndirectedEdge] 4, 1 \[UndirectedEdge] 5}


I'm finding that the 'If' statement

If[(1 \[UndirectedEdge] 1) ∈ edges,1,0]


does not return 1, as expected, or even return zero. It simply spits back the full conditional,

If[1 \[UndirectedEdge] 1 ∈ {1 \[UndirectedEdge] 1,
1 \[UndirectedEdge] 2, 1 \[UndirectedEdge] 3,
1 \[UndirectedEdge] 4, 1 \[UndirectedEdge] 5}, 1, 0]


Why is this happening?

• try If[MemberQ[edges, 1 \[UndirectedEdge] 1], 1, 0]? – kglr Aug 27 '19 at 15:33
• also Boole @ EdgeQ[Graph@edges,1 \[UndirectedEdge] 1] – kglr Aug 27 '19 at 16:24

Element[a,dom] tests whether a is an element of the domain Dom. The documentation for the function lists what those domains might be, things like Reals and Integers, but not lists that you have defined yourself. So, for example

1 \[Element] {1, 2, 3}

also returns unevaluated whereas

1 \[Element] Integers

returns

True.

And I see that @kglr has already told you what to do, use MemberQ to test membership of arbitrary lists, thusly

If[MemberQ[edges, 1 \[UndirectedEdge] 1], 1, 0]

which returns

True`.

• ah, thanks a lot! – Joe Aug 27 '19 at 16:00