Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
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 – Rojo Jun 19 '12 at 18:55
@Rojo our answers are eerily similar. – Heike Jun 19 '12 at 18:57
Yeah, +1 for you on behalf of both – Rojo Jun 19 '12 at 19:00
Thanks. I'm sure I'll even the score one day :-) – Heike Jun 19 '12 at 19:06
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? – james Jun 19 '12 at 19:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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