%%
%% % Hk timesL
%n
77 ^ 2
Out[1]= 5929
%+1
5930
This uses both the last result, and the result before that.
In[3]:=
Out[3]=
3 % + % ^ 2 + %%
35 188 619
You will have noticed that all the input and output lines in Mathematica are numbered. You can
use these numbers to refer to previous results.
This adds the results on lines 2 and 3 above.
In[4]:=
Out[4]=
%2 + %3
35 194 549
If you use a text-based interface to Mathematica, then successive input and output lines will
always appear in order. However, if you use a notebook interface to Mathematica, as discussed
in "Notebook Interfaces", then successive input and output lines need not appear in order. You
can for example "scroll back" and insert your next calculation wherever you want in the note-
Core Language
You can replace x with any expression. Here every occurrence of x is replaced by 2 - y.
In[2]:=
Out[2]=
1 + x + x ^ 2 . x -> 2 - y
3 + H2 - yL2 - y
Here is a transformation rule. Mathematica treats it like any other symbolic expression.
In[3]:=
Out[3]=
x -> 3 + y
x3+y
This applies the transformation rule on the previous line to the expression x ^ 2 - 9.
In[4]:=
Out[4]=
x ^ 2 - 9 . %
-9 + H3 + yL2
expr.x->value
expr.8x->xval,y->yval<
The replacement operator . allows you to apply transformation rules to a particular expression. Sometimes, however, you will want to define transformation rules that should always be
applied. For example, you might want to replace x with 3 whenever x occurs.
As discussed in "Defining Variables", you can do this by assigning the value 3 to x using x = 3.
Once you have made the assignment x = 3, x will always be replaced by 3, whenever it
appears.
This assigns the value 3 to x.
In[6]:=
Out[6]=
x=3
3
x^2 - 1
8
Core Language
335
Input of Boxes
Use a palette
Use control keys
Ways to input boxes.
Control Keys
Ctrl+2 or Ctrl+@
square root
Ctrl+5 or Ctrl+%
Ctrl+6 or Ctrl+^
superscript
Ctrl+7 or Ctrl+&
overscript
Ctrl+9 or Ctrl+(
Ctrl+0 or Ctrl+)
Ctrl+- or Ctrl+_
subscript
Ctrl+= or Ctrl+Plus
underscript
Ctrl+Enter
Ctrl+,
Ctrl+.
Ctrl+/
fraction
Ctrl+Space
On English-language keyboards both forms will work where alternates are given. On other
keyboards the first form should work but the second may not.