<|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.

  • 5
    $\begingroup$ 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. $\endgroup$
    – C. E.
    Commented Jun 1, 2015 at 15:59
  • $\begingroup$ 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. $\endgroup$
    – Rho Phi
    Commented Jun 1, 2015 at 16:11
  • 3
    $\begingroup$ @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. $\endgroup$
    – Mr.Wizard
    Commented Jun 1, 2015 at 16:14
  • $\begingroup$ 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? $\endgroup$
    – Rho Phi
    Commented Jun 2, 2015 at 9:08
  • 3
    $\begingroup$ This is indeed a deliberate design decision. There is an undocumented version of Association that does not care about order: Data`UnorderedAssociation. $\endgroup$
    – Stefan R
    Commented Jun 3, 2015 at 19:26

1 Answer 1


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

Quantity[5, "Percent"] == 0.05

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|>

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]
  • $\begingroup$ 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. $\endgroup$
    – Rho Phi
    Commented Jun 2, 2015 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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