# when two associations are equal?

<|a -> 2, b -> 3|> == <|b -> 3, a -> 2|> returns False; can anybody explain why? If I am not mistaken here these two associations would be identical from the practical point of view.

• The developers of Mathematica do not agree with you, or they would have given Association the Orderless property. With this property those two associations would indeed be equal. You can use Attributes[Association] to confirm that Association does not have that property. Maybe someone knows why this is, let's see. Commented Jun 1, 2015 at 15:59
• Thanks for the comment. Indeed I was tried to mimic what Options do, which seems to be not caring of the order they are given. Commented Jun 1, 2015 at 16:11
• @Roberto The order of options do matter in the sense that earlier options will override later options. This is actually the reverse of associations where later entries override earlier ones. I am not sure what you are attempting but be careful. Commented Jun 1, 2015 at 16:14
• It's true that if you write a->something many times you might not realizing that later you are overwriting your assignment, but isn't it the same for variable assignment with =? I mean a=2; b=3; a=something is the same as <| a->2, b->3, a->something |> ... right? Commented Jun 2, 2015 at 9:08
• This is indeed a deliberate design decision. There is an undocumented version of Association that does not care about order: DataUnorderedAssociation. Commented Jun 3, 2015 at 19:26

Perhaps as Pickett describes the developers do not consider these associations Equal since that function performs other conversions like:

Quantity[5, "Percent"] == 0.05

True


But perhaps Equal has not been (properly?) extended to associations yet as 2.0 and 2 are Equal but these are not:

<|a -> 2|> == <|a -> 2.0|>

False


Depending on what you are doing this might be useful, but beware it does not have early exit (short-circuit) behavior:

eq[{x_}] = False;
eq[{x__}] := Equal[x]

one = <|a -> 2, b -> 3|>;
two = <|b -> 3, a -> 2.0|>;

And @@ Merge[{one, two}, eq]

True

• Thanks a lot for this detailed investigation of the fact. I think that <|a -> 2|> == <|a -> 2.0|> being False` points towards a bug, rather than a feature. Commented Jun 2, 2015 at 9:05