# Postfix Double Slash Notation with Multiple Parameters [duplicate]

Examples

A convenient shorthand that I use frequently is the "double slash" notation to string commands together. For example, I can write:

x - 1 + x^2 //TraditionalForm


x^2 + x - 1


Or another example:

(x - 1)(x + 2) //Expand //TraditionalForm


Yields:

x^2 + x - 2


However, I have never been able to find a way to input multiple arguments into a function using this notation. That is, I cannot call something like:

x^2 + 9x + 5, 3 //PolynomialMod


Obviously the above can easily be written as:

PolynomialMod[x^2 + 9x + 5, 3]


(but what's the fun in that?)

Question

Is there a way to input multiple parameters using the shorthand postfix operator?

## marked as duplicate by Mr.Wizard♦Oct 13 '14 at 5:38

A lot of functions in MMA have default values for Optional Arguments, for Example Flatten. It can take Flatten[expr] which means Flatten[expr, Infinity]

Some functions don't have such option and you need to feed the Optional Arguments but you can go around by building your own function

for your example, you can do this kind of trick like this:

f[expr_, n_: 3] := PolynomialMod[expr, n]


now

x^2 + 9 x + 5 // f
2 + x^2


In this case you will have fixed value for Optional Arguments which is 3 and if you need to use this method with other value than 3 you need to change 3 in the definition of f above. However, an easy way to do it is as follows:

x^2 + 9 x + 5 // PolynomialMod[#, 3] &

• I'd say the last line is the definite answer to the question (i.e. using a pure function with multiple arguments). – Yves Klett Oct 7 '14 at 4:27
• The last line is exactly what I was looking for, thanks! – therealrootuser Oct 7 '14 at 6:39
• @YvesKlett, it was the definitive answer until V10 operator forms. – alancalvitti Oct 7 '14 at 17:57
• @alancalvitti why not post another answer to that regard? – Yves Klett Oct 8 '14 at 3:42
• @YvesKlett, I'll post it as a question as op form doesn't currentyl support variadics for example. I don't have a ready answer. – alancalvitti Oct 8 '14 at 4:09

Algohi's answer is the most appropriate if one of the function's arguments is primary and the others secondary. However, you can get closer to the syntax that you suggested in your question using

{x^2 + 9 x + 5, 3} // Apply @ PolynomialMod


which works in version 10 using the operator form of Apply.

Or, to include earlier versions, you could define your own "postfix" operator like

Colon[list_, f_] := f @@ list


Then you can write

{x^2 + 9x + 5, 3} ∶ PolynomialMod


That's the \[Colon] character, also entered as Esc:Esc, or you could use any other infix operator with no built-in meaning.

You should use Sequence

PolynomialMod[x^2 + 9 x + 5, 3]

PolynomialMod@Sequence[x^2 + 9 x + 5, 3]

Sequence[x^2 + 9 x + 5, 3] // PolynomialMod
2 + x^2


all produce the same output.

Works with any function

Sequence[i, {i, 10}] // Table
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}


You can do (but only for two arguments)

x^2 + 9x + 5 ~ PolynomialMod ~ 3

• Using the infix notation is an interesting idea, but as you pointed out, it only seems to work on two arguments. And it is a side-step to being able to do this with postfix notation, which is what I want. – therealrootuser Oct 7 '14 at 3:11
• While there are several huge infixionados around and infix is useful stuff , this is not actually answering the question... – Yves Klett Oct 7 '14 at 4:32
• Interesting, but hard to read, as infixes tend to be, except perhaps in the case of Join: a ~ Join ~ b. – asterix314 Oct 7 '14 at 6:24
• @asterix314 ... well... 1+1 is easy to parse :-) – Yves Klett Oct 7 '14 at 11:51

Sometimes you can use new Mathematica operator forms (V10+)

{-5, -3, -1, 2, 4, 6} // SortBy[Abs]


{-1, 2, -3, 4, -5, 6}

• But operator forms have similar limitation as // in terms of handling variable number of arguments. – alancalvitti Oct 7 '14 at 17:59