Using Mathematica » Interface
Mathematica has a series of useful function aliases that make coding more concise and readable.
Technically, these are called infix operators , a term that also encapsulates
- , and
* , but that's unimportant for their usage here.
@ alias is like a pair of square brackets. The following illustrates its usage:
It only applies to a single argument however. For example, Mathematica will not evaluate the following command
/@ takes a function and applies to every element in a list, returning the list of results. Example:
When using this alias care should be taken that the right-hand side is wrapped in parentheses, as was done above, if it's more than just a simple list.
@@ applies a function to all the arguments in a list. That is, the elements of the list become the arguments to the function. Example:
// is more or less a reversed form of
@ . Example:
But there is a small difference in terms of how the two work with other operators.
Consider you're trying to apply the function
f to the list of results generated by using
One might first try the following:
This clearly doesn't work.
f is applied to
g before being mapped across
In this case there are two options:
/@ evaluates before
// , this works. What is said is that
// has a low precedence .
Precedences for any operator can be checked using the function
Precedence , if the function name is known. Function names for a given operator can be found by selecting the operator and using – –F on Mac or F1 on Windows.
For example, knowing that
// is an alias for the function
And we'll compare that to the function
Prefix for which
@ is an alias
~ takes a function and applies it to the preceding and following arguments as follows:
This is useful and worth knowing, but it can often be cleaner simply to use
@@ , potentially in combination with
@* takes a two functions and composes them. For example:
This is particularly useful when negating a function, that is, applying the
Not function to it. We can make a simple
NotTrueQ function by doing this:
NotTrueQ=(Not@*TrueQ); NotTrueQ@1 NotTrueQ@False NotTrueQ@True