I have spent three hours debugging some code and at the end I think I found a bug. Otherwise I cannot explain what I am seeing:

When I want to use RankedMax on nested sublists, Mathematica freaks out, but it works all smooth as I expect when I use Max.


tab = Table[{i, j, k}, {i, 1, 2}, {j, 1, 3}, {k, 1, 4}] // TableForm
Map[Function[{x}, x/Max[x]], tab] // TableForm
Map[Function[{x}, x/RankedMax[x, 1]], tab] // TableForm

The last line will cause an error, and I do not understand why, because the documentation says:

RankedMax[{Subscript[x, 1],...,Subscript[x, m]},1] is equivalent to Max[{Subscript[x, 1],...,Subscript[x, m]}].

Why is this happening? Do I understand something incorrectly?


1 Answer 1


I suspect this has to do with the fact that Max has attribute Flat, and RankedMax hasn't. To get the same behaviour, you could do

(tab = Table[{i, j, k}, {i, 1, 2}, {j, 1, 3}, {k, 1, 4}]) // TableForm
Map[Function[{x}, x/Max[x]], tab] // TableForm
Map[Function[{x}, x/RankedMax[Flatten[x], 1]], tab] // TableForm

As an aside, // binds stronger than = which means that is you do something like

a = b // TableForm

this is interpreted as a = TableForm[b] which is probably not what you want if you want to use a for further calculations. To prevent this you can use brackets to group the right terms together, i.e. (a = b) // TableForm.

  • $\begingroup$ I lost my internet connection while posting, thought it had posted. Now I see that it only posted it when my connection got back so I'm deleting it. It's too similar $\endgroup$
    – Rojo
    Jun 19, 2012 at 18:55
  • $\begingroup$ @Rojo our answers are eerily similar. $\endgroup$
    – Heike
    Jun 19, 2012 at 18:57
  • $\begingroup$ Yeah, +1 for you on behalf of both $\endgroup$
    – Rojo
    Jun 19, 2012 at 19:00
  • $\begingroup$ Thanks. I'm sure I'll even the score one day :-) $\endgroup$
    – Heike
    Jun 19, 2012 at 19:06
  • $\begingroup$ Thank you for making this a little bit more clear. I didn't know that // binds stronger, but I would have found out one day... regarding the "feature": how can I know and expect this behaviour? How can I check the "attributes" of the functions? Is there anything else that can go wrong if the documentation says they are equivalent when in fact they are not? $\endgroup$
    – james
    Jun 19, 2012 at 19:45

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.