Everything Is an Expression

Mathematica handles many different kinds of things: mathematical formulas, lists, and graphics, to name a few. Although they often look very different, Mathematica represents all of these things in one uniform way. They are all expressions.

A prototypical example of a Mathematica expression is . You might use to represent a mathematical function . The function is named , and it has two arguments, and .

You do not always have to write expressions in the form . For example, is also an expression. When you type in , Mathematica converts it to the standard form Plus[x, y]. Then, when it prints it out again, it gives it as .

The same is true of other "operators", such as (Power) and (Divide).

In fact, everything you type into Mathematica is treated as an expression.

x+y+zPlus[x,y,z]
xyzTimes[x,y,z]
x^nPower[x,n]
{a,b,c}List[a,b,c]
a->bRule[a,b]
a=bSet[a,b]

Some examples of Mathematica expressions.

You can see the full form of any expression by using FullForm[expr].

Here is an expression.
In[1]:=
Click for copyable input
Out[1]=
This is the full form of the expression.
In[2]:=
Click for copyable input
Out[2]//FullForm=
Here is another expression.
In[3]:=
Click for copyable input
Out[3]=
Its full form has several nested pieces.
In[4]:=
Click for copyable input
Out[4]//FullForm=

The object f in an expression is known as the head of the expression. You can extract it using Head[expr]. Particularly when you write programs in Mathematica, you will often want to test the head of an expression to find out what kind of thing the expression is.

Head gives the "function name" .
In[5]:=
Click for copyable input
Out[5]=
Here Head gives the name of the "operator".
In[6]:=
Click for copyable input
Out[6]=
Everything has a head.
In[7]:=
Click for copyable input
Out[7]=
Numbers also have heads.
In[8]:=
Click for copyable input
Out[8]=
You can distinguish different kinds of numbers by their heads.
In[9]:=
Click for copyable input
Out[9]=
Head[expr]give the head of an expression: the f in
FullForm[expr]display an expression in the full form used by Mathematica

Functions for manipulating expressions.

New to Mathematica? Find your learning path »
Have a question? Ask support »