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
And receive back:
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?
See also: http://reference.wolfram.com/language/ref/Postfix.html
Answer
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] &
Comments
Post a Comment