How to | Use Shorthand Notations

Shorthand notations are a part of Mathematica's rich syntax system that allows multiple ways to feed arguments to functions. In addition to creating compact code, using shorthand notation lets you customize your workflow in Mathematica.

Mathematica provides several convenient methods for entering functions.

For example, use Length with square brackets around a list to get the length of the list:

In[1]:=
Click for copyable input
Out[1]=

Using the symbol between the function and the list does the same thing. With you do not have to move to the end of the expression to match the square bracket:

In[2]:=
Click for copyable input
Out[2]=

You can also use the postfix notation:

In[3]:=
Click for copyable input
Out[3]=

These notations extend to any function and any kind of argument:

In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=
In[6]:=
Click for copyable input
Out[6]=

You can also use infix notation for functions that take two arguments:

In[7]:=
Click for copyable input
Out[7]=
    

Pure functions are used very often in Mathematica. They let you use a function without having to define an explicit name for it. You can use the shorthand notation for Function to give a pure function.

Use Function to give a pure function that raises the input to a cubic power:

In[8]:=
Click for copyable input
Out[8]=

The and symbols can be combined to accomplish the same thing. The symbol serves as the placeholder for the variable, while the symbol precedes the value you wish to substitute into the function:

In[9]:=
Click for copyable input
Out[9]=
    

Map and Apply are essential to functional programming. Using the shorthand notations for these functions is very convenient.

Use Map to map a function over the elements of a list:

In[10]:=
Click for copyable input
Out[10]=

Using does the same thing:

In[11]:=
Click for copyable input
Out[11]=

Apply has a shorthand notation as well ():

In[12]:=
Click for copyable input
Out[12]=
In[13]:=
Click for copyable input
Out[13]=
    

Shorthand notations in Mathematica can also be combined to produce efficient code.

Use Map and Function to raise each element of a list to a power and add a symbol to the result:

In[14]:=
Click for copyable input
Out[14]=

Perform the same operation using the shorthand notation for Function:

In[15]:=
Click for copyable input
Out[15]=

Extend this to include the shorthand notation for Map:

In[16]:=
Click for copyable input
Out[16]=
    

You will often need to use previous output in a new computation. This can be done by using the symbol, the shorthand notation for Out.

Set up a computation:

In[17]:=
Click for copyable input
Out[17]=

Use the shorthand notation for Out, the symbol, to specify the most recent output:

In[18]:=
Click for copyable input
Out[18]=

Use with the shorthand notation for Part, , to take the first element of the list:

In[19]:=
Click for copyable input
Out[19]=

You can use ... to refer to previous outputs. Get the output generated two computations ago:

In[20]:=
Click for copyable input
Out[20]=

If you want to get the output from a computation that is not recent, using many symbols can be cumbersome.

Instead, use the specific output cell number with Out. If you evaluate this cell, you will get Out[17] from your current Mathematica session and not necessarily what is shown here:

In[28]:=
Click for copyable input
Out[28]=

Here is another shorthand notation:

In[29]:=
Click for copyable input
Out[29]=

While convenient, referring to previous output by label or shorthand notation can quickly get out of hand since the current evaluation is always bound to the earlier output. Therefore, you must ensure that the output you want to use is available to your current computation. It is advised that you use this notation with caution.

    

Working with strings can be simplified by using shorthand notations for string manipulation functions.

Joining strings together is a frequently used string operation. Do this with StringJoin:

In[30]:=
Click for copyable input
Out[30]=

Using the shorthand notation for StringJoin, , this same operation can be written as:

In[31]:=
Click for copyable input
Out[31]=

StringExpression is a very important function that is used to represent strings. It is used by a number of string manipulation functions such as StringReplace, StringCases, StringSplit, and StringMatchQ.

Use StringExpression to create a string expression object:

In[25]:=
Click for copyable input
Out[25]=

Or directly use , the shorthand notation for StringExpression:

In[26]:=
Click for copyable input
Out[26]=
New to Mathematica? Find your learning path »
Have a question? Ask support »