# How exactly does Postfix notation work?

I guess I've been using the Postfix notation // wrongly for some time now. I assumed it was a quick way to apply a function to all that precedes it. Now I was surprised by the fact that for example

a // f /. a -> 1


outputs

f[a]


I would have expected this to either be the same as (a // f) /. a ->1, or as applying the replacement rule first and then the function (a /. a -> 1) // f. However, both would output f[1].

Examining a // f with FullForm (and Hold) does not give me any insight to what is happening either.

The Postfix documentation is unfortunately very limited. This seems rather trivial, so sorry if this has been asked before, but I couldn't find any post about this.

• Try evaluating this: FullForm[Hold[a // f /. a -> 1]], it should help (in general) understanding the order of operations Mathematica invokes. – user6014 May 8 '17 at 14:08
• The wily programmer uses parentheses to exactly guarantee order of operations. I use "//" lots, and have been bitten by it before. – MikeY May 8 '17 at 14:12

I would have expected this to either be the same as (a // f) /.a ->1, or as applying the replacement rule first and then the function (a /.a->1)//f

It is neither of those. It is a precedence issue. It is interpreted as

a // (f /. a -> 1)


You can look it up, or you can check it like this:

PrecedenceForm@HoldForm[a // f /. a -> 1]

(* (f /. a -> 1)[a] *)


Comment from @andre:

To see precedences you can also select a then extend the selection (with multi-click on a or with ctrl-shift-. on Windows (ctrl-. on Mac). Then observe the size of the blocks by wich the selection extends. Very useful, I use it all the time.

• To see precedences you can also select a then extend the selection (with multi-click on a or with Ctrl-Shit-. on windows. Then observe the size of the blocks by wich the selection extends. Very usefull, I use it alt the time. – andre314 May 8 '17 at 14:11
• @Szabolcs, thank you. I don't know why I didn't consider that possibility for precedence. Thanks also especially for including `PrecedenceForm@HoldForm'. – Kvothe May 8 '17 at 14:31