Group Abstract Group Abstract

Message Boards Message Boards

1
|
6.7K Views
|
3 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Why is UndirectedEdge[a, b] === UndirectedEdge[b, a] false?

I expected the following assertion to return a value of True but Mathematica 11 returns a value of False

UndirectedEdge[a, b] === UndirectedEdge[b, a]

If the above is "correct" to return a value of False, then my followup question is to ask what function do I apply so as to reduce a list UndirectedEdges holding what I believe to be duplicates into a minimal list of UndirectedEdge elements? e.g., what aFunction is applied so that the following would return a value of True?

aFunction[{UndirectedEdge[a, b], UndirectedEdge[b, a], UndirectedEdge[c, d], UndirectedEdge[d,c]}] === {UndirectedEdge[a, b], UndirectedEdge[c, d]}
POSTED BY: Chase Turner
3 Replies
POSTED BY: Szabolcs Horvát

This is because UndirectedEdge does not have the property Orderless:

Attributes[UndirectedEdge]

However you can add it:

SetAttributes[UndirectedEdge, Orderless]

And when you do so:

UndirectedEdge[a, b] === UndirectedEdge[b, a]

it will return True... It might affect other pieces of Mathematica as well, so be careful when changing the Attributes of built-in functions! Otherwise make your own SameQ function, that checks explicitly both permutations.

POSTED BY: Sander Huisman

Thank you -- both for the workaround and warning about possible side effects on other parts of the Mathematica system!

POSTED BY: Chase Turner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard