Introduction to Mathematica

To start this slide show, click the start button:

Clicking start will open a palette with nine buttons:

The next button shows the next slide

The back button shows the previous slide

The first button jumps to the first slide

The skip button skips to the next section

The notes button shows (or hides) lecture notes

The demo button includes examples intended for manual demonstration

The stop button stops the kernel

The reset button attempts error recovery

The close button closes all of the notebooks used in this slide show

Begin["SlideShow`"];

SlideShow`source = 
        With[{nb = 
              Select[Notebooks[], 
                SameQ[WindowTitle /. 
                      Options[#], "Source for Introduction to \
Mathematica"] &]}, 
          If[Length[nb] > 0, nb[[1]], 
            NotebookPut[
              Notebook[{Cell["No source notebook", "Text", 
                    FontSize -> 24, ShowCellBracket -> False]}, 
                WindowSize -> {250, 70}, 
                WindowMargins -> {{340, Automatic}, {Automatic, 200}}, 
                WindowTitle -> "Error", WindowElements -> {}, 
                WindowFrameElements -> "CloseBox"]]]];

SlideShow`nb = 
        With[{nb = 
              Select[Notebooks[], 
                SameQ[WindowTitle /. 
                      Options[#], "Introduction to Mathematica"] &]}, 
          If[Length[nb] > 0, nb[[1]], 
            NotebookCreate[
              WindowTitle -> "Introduction to Mathematica", 
              Magnification -> 2, WindowSize -> {760, 560}, 
              WindowMargins -> {{20, Automatic}, {Automatic, 20}}, 
              DelimiterFlashTime -> 0, 
              StyleDefinitions -> "Training.nb", 
              ScreenStyleEnvironment -> "Slides"]]];

SlideShow`notes = 
        With[{nb = 
              Select[Notebooks[], 
                SameQ[WindowTitle /. Options[#], "notes"] &]}, 
          If[Length[nb] > 0, nb[[1]], 
            NotebookCreate[Visible -> True, WindowTitle -> "notes", 
              WindowSize -> {520, 120}, 
              WindowMargins -> {{20, Automatic}, {20, 
                    Automatic}}]]];

SlideShow`$EvaluationToggle = False;

SlideShow`ShortPause := Do[2 + 2, {10000}]

SlideShow`TypeInput[p_] := 
      If[StringQ[p], 
        Scan[(NotebookWrite[nb, #]; ShortPause) &, Characters[p]], 
        NotebookWrite[nb, p]]

SlideShow`HeadingCell[data_] := 
      MemberQ[{"Title", "Section", "Subsection"}, 
        Part[NestWhile[First, 
            data, (Head[#] =!= Cell || Length[#] < 2) &], 2]]

SlideShow`ShowSlide[data_]:=

\(SlideShow`NextSlide[p_] := 
      If[$EvaluationToggle, $EvaluationToggle = False; 
        FrontEndExecute[FrontEndToken[nb, "EvaluateCells"]], 
        Module[{data}, SelectionMove[source, Next, CellGroup]; 
          data = NotebookRead[source]; 
          If[data === {}, SelectionMove[source, Previous, CellGroup], 
            If[First[data] === "start demo", 
              If[p, SelectionMove[source, Next, CellGroup]; 
                data = NotebookRead[source], 
                NotebookFind[source, "end demo", Next]; 
                SelectionMove[source, Next, CellGroup]; 
                data = NotebookRead[source]]]; 
            If[First[data] === "end demo", 
              SelectionMove[source, Next, CellGroup]; 
              data = NotebookRead[source]]; 
            If[SameQ[Last[data], CellTags -> "notes"], 
              FrontEndExecute[{FrontEndToken[notes, "SelectAll"], 
                  FrontEndToken[source, "Copy"], 
                  FrontEndToken[notes, "Paste"], 
                  FrontEndToken[notes, "ScrollNotebookStart"]}]; 
              SelectionMove[source, Next, CellGroup]; 
              data = NotebookRead[source]]; 
            If[Last[data] === "Input", 
$EvaluationToggle = True; 
              SelectionMove[nb, After, Notebook]; 
              TypeInput[data[\([1]\)]], 
If[
                SameQ[Last[data], 
                  CellTags -> "evaluate"], \($Line--\); 
                FrontEndExecute[FrontEndToken[source, "EvaluateCells"]], 
                If[HeadingCell[data], 
                  FrontEndExecute[{FrontEndToken[source, "Copy"], 
                      FrontEndToken[nb, "SelectAll"], 
                      FrontEndToken[nb, "Paste"], 
                      FrontEndToken[nb, "ScrollNotebookStart"]}], 
                  SelectionMove[nb, After, Notebook]; 
                  NotebookWrite[nb, data]]]]]]]\)

SlideShow`NotesToggle := 
      SetOptions[notes,  
        Visible -> Not[TrueQ[Visible /. Options[notes]]]]

SlideShow`PreviousSlide := 
        Module[{data}, 
$EvaluationToggle = False; 
          While[SelectionMove[source, Previous, CellGroup]; 
            data = NotebookRead[source]; 
            Which[First[
                  data] === "end demo", 
NotebookFind[
                source, "start demo", Previous]; True, HeadingCell[data], 
              SelectionMove[source, Previous, Cell]; 
              SelectionMove[source, Before, Cell]; NextSlide[True]; False, 
              Last[data] === (CellTags -> "first"), 
              NextSlide[True]; False, True, True]]];

SlideShow`FirstSlide := ($EvaluationToggle = False; 
        NotebookFind[source, "first", All, CellTags]; 
        SetSelectedNotebook[notes]; 
        SetSelectedNotebook[nb]; 
FrontEndExecute[
          FrontEndToken[source, "EvaluateCells"]])

If[SlideShow`$ShowFirstSlide, SlideShow`$ShowFirstSlide = False; 
      SlideShow`FirstSlide]

SlideShow`SkipSlide := ($EvaluationToggle = False; 
        While[SelectionMove[source, Next, CellGroup]; 
          data = NotebookRead[source]; 
          Which[data === {}, SelectionMove[source, Previous, CellGroup]; 
            False, First[data] === "start demo", 
            NotebookFind[source, "end demo", Next]; True, 
            HeadingCell[data], SelectionMove[source, Previous, Cell]; 
            SelectionMove[source, Before, Cell]; 
NextSlide[
              True]; False, True, True]])

SetSelectedNotebook[nb]; End[]; $Line = 0;

$Line = 0; SlideShow`NextSlide[True];

Welcome to the Introduction to Mathematica training course.
The purpose of this course is to provide specific step-by-step information about doing basic calculations with Mathematica, to provide a more general tour of other features of the system, and to point out sources for more information.
[Quit Mathematica to demonstrate basic features. Click the demo button to step through a typical demonstration. This demonstration is more effective if done live.]

Introduction to Mathematica

start demo

I would like to start at the beginning, or not quite at the beginning, because the first step is to install Mathematica on your computer, and I am not going to talk about installation here except to mention that there are an infinite number of ways to configure a computer and as a result there are an infinite number of issues that might come up during installation, since installation is a very system-dependent task. Usually installation works without difficulty following the printed instructions that came with your copy of Mathematica, and if you have trouble you can either contact someone who is an expert about the configuration of your computer or contact Wolfram Research technical support.

Introduction to Mathematica

So assuming that Mathematica is already installed, the first step is to start the program. If you know how to start other applications on your computer, then starting Mathematica should work in basically the same way, but that way will be different on different types of computers.  For more information, see the Getting Started booklet that came with your copy of Mathematica. An online version of the Getting Started booklet is included in the Getting Started/Demos section of the Help Browser.

Starting Mathematica

Windows: Open the Start menu, point to Programs, and choose Mathematica from the Mathematica program group.

Macintosh: Double-click the Mathematica icon inside the Mathematica folder.

X/Unix/Linux: In a shell, type mathematica.

Your computer may be set up so that there are other ways to start Mathematica.

After Mathematica starts up, after a default installation, you should find on your computer screen a menu bar, a large empty window, and another smaller window called a palette.
The menu bar includes items like a File menu and an Edit menu that work much like the corresponding menus that you see when you use other applications, and several menu items that are specific to Mathematica.

Interface elements

Menu bar

Main input/output window

One or more palette windows (optional)

The large empty window is called a notebook window.  The documents that you edit using Mathematica are called notebooks. This window shows the contents of a notebook. The window you normally see at startup is a new, empty notebook, so the window will be empty. This is the window into which you will enter your input and in which Mathematica will display your results.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SlideShow`sample = 
        NotebookCreate[Magnification -> 3];

The third item on your computer screen is called a palette.  This palette is a collection of buttons that provide a convenient way of entering certain kinds of input. I will give some examples of that later in this session.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

NotebookOpen["BasicInput.nb"];

Returning now to the main input output window, to enter your input, just start typing.

Entering and evaluating input

To enter input, just start typing

SetSelectedNotebook[SlideShow`sample];

Scan[(NotebookWrite[SlideShow`sample, #]; SlideShow`ShortPause) &, 
      Characters["2+2"]]

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb]; SlideShow`NextSlide[True];

Now I want to tell Mathematica to do this calculation, or in Mathematica terminology, I want to tell Mathematica to evaluate this input. There are several ways to do that, the most common of which is to press the return key while holding down the shift key.

To evaluate input, press the return key while holding down the shift key.

SetSelectedNotebook[SlideShow`sample];

FrontEndExecute[
        FrontEndToken[SlideShow`sample, "EvaluateCells"]];

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb]; SlideShow`NextSlide[True]

To enter another calculation, just continue typing.

To enter another calculation, just continue typing

SetSelectedNotebook[SlideShow`sample];

Scan[(NotebookWrite[SlideShow`sample, #]; SlideShow`ShortPause) &, 
      Characters["3+3"]]

FrontEndExecute[
      FrontEndToken[SlideShow`sample, "EvaluateCells"]]

If any of this doesn't work it is probably either because of something that you did, such as clicking outside of this window after entering your input, which would select another application, in which case the solution is to find out what you did, or because of some sort of installation problem, so that Mathematica is for example not able to launch the part of Mathematica that does the calculations, in which case the problem would be approached just like any other installation problem.
There are rarely any difficulties at this stage however. Installation usually works, and difficult problems after that are very rare.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

Before moving on I would like to remark that saving, closing, and opening notebook files works essentially as it does in other applications.
For example, you can save a notebook by selecting Save or Save As from the File menu.

Saving and opening notebooks

Save notebooks using Save from the File menu

Close notebooks using Close from the File menu

Create new notebooks using New from the File menu

Open notebooks using Open from the File menu

SetSelectedNotebook[SlideShow`sample];

NotebookSave[SlideShow`sample];

You can close a notebook by selecting Close from the File menu.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SetSelectedNotebook[SlideShow`sample];

NotebookClose[SlideShow`sample]

You can create a new notebook by selecting New from the File menu.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SlideShow`new = NotebookCreate[];

Or you can re-open the saved notebook to continue working in that notebook using Open from the File menu.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SlideShow`sample = Notebooks[]; 
    FrontEndExecute[FrontEndToken["Open"]]; 
    SlideShow`sample = Complement[Notebooks[], 
          SlideShow`sample][[1]];

And there are keyboard equivalents for all of these things
[list keyboard commands for opening, closing and saving notebooks]
[Ask for questions.]
[Open the slide show notebook, without narration]
[Advance to the first slide, giving the outline of the talk]

NotebookClose[SlideShow`sample]; NotebookClose[SlideShow`new]; 
    SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

end demo

Here is an outline for the remainder of this session.
Getting started we just discussed.
Under Basic inputs, which is the next topic, I want to go over a fairly detailed discussion of the basic principles of Mathematica syntax.
After that the next topic, tour of built-in functions, is a rather less detailed survey of calculations you can do using Mathematica and without doing any programming.
Then I want to describe some formatting and typesetting and other things you can do with this notebook interface that we've been looking at.
Next I want to spend a least a few minutes talking about programming in Mathematica. Certainly a few minutes isn't enough to do justice to this subject, but programming is so important that it seems worthwhile to mention it at least briefly.
And finally I want to point out additional sources of information and in particular point out some things that might be of special interest when getting started.

Introduction to Mathematica

As described earlier, to enter your input you just start typing, and to evaluate that input press the return key while holding down the shift key.

First calculations

To enter your input, just start typing

To evaluate your input, press the return or enter key while holding down the shift key.

For example.
[click to evaluate]
To move beyond two plus two it is useful to learn a bit more about Mathematica syntax.

2+2

Arithmetic is entered using the same standard notations that you find in other computer programs and in traditional mathematics.  A plus sign means addition, a minus sign means subtraction, and so forth.

Arithmetic

({{x + y + z, add}, {-x, minus}, {x - y, subtract}, {x/y, divide}, {x y z or x*y*z, multiply}, {x^y, power}, {x (y + z), grouping}})

In computer programming languages the most common way to indicate multiplication is with an asterisk. For example, this input indicates two multiplied by three.

2*3

In traditional mathematical notation just putting two factors next to each other, usually with a space to separate the factors, also indicates multiplication, and you can do the same thing in Mathematica.

2 3

If there is no chance of misunderstanding, as in this input where one of the factors is enclosed in parentheses, then you don't even need a space.  This input means two multipled by 3 plus 4.

2(3+4)

In an example such as this one, the space is obviously important, since without a space between the 2 and the 3, this is the integer 23, rather than 2 multipled by 3.

23

This isn't usually a problem when working with numbers, but when working with variables it useful to keep in mind that an input like this is x plus x multipled by 2

x+x 2

But if there is no space between the x and the 2, this input introduces a new variable x2.

x+x2

In cases such as this, some people choose to include an asterisk just to eliminate any ambiguity. In most cases, however, whether or not to include an asterisk to indicate multiplication is a matter of personal preference.

x+x*2

This input with the carat character means 2 raised to the power 3. This is a common notation for powers in computer languages.

2^3

Of course the traditional notation for powers looks more like this, where the power is indicated by a superscript. [click to evaluate] This input means the same thing as the previous input with the carat character. This notation is easy to enter too, and will be described later in this video in the segment on typesetting.

(2^3)

Before leaving the subject of arithmetic, if you watch closely as this input is entered, the opening parentheses are a different color until the closing parentheses are entered, and the opening parentheses flash when the closing parentheses are entered. You can turn this off if you find it distracting, but this feature can be very useful for quickly finding out how the parentheses in an expression match up.

SetOptions[SlideShow`nb, DelimiterFlashTime -> 0.5]; 
    SlideShow`TypeInput["2(3+4(5+6))"]; 
    SetOptions[SlideShow`nb, DelimiterFlashTime -> 0];

You can also use symbolic variables like x and y in your inputs.

Inputs with variables

This input means x plus y cubed. [click to evaluate] This input just evaluates to itself, because nothing has been specified to be done with it.

(x+y)^3

Of course there are lots of operations that can be done on symbolic expressions. This example shows a function called Expand that expands out this expression into a sum of terms.
[click to evaluate]
This one input illustrates all of the basic principles of Mathematica syntax. The function that is used in this example is called Expand, with a capital E, then the argument of the function enclosed in square brackets, and these special notations like the plus sign and the carat character for things like addition and exponents.
Nearly all Mathematica inputs follow this pattern, which the name of a function followed by the arguments of the function enclosed in square brackets. The only exceptions are when you are using special notations like the plus sign and the carat character.

Expand[(x+y)^3]

With these examples in mind, here is a look at all of the basic conventions of Mathematica input.

Conventions in Mathematica input

Mathematica inputs are case sensitive, which means that capitalization is important.

For example, Expand with a capital E and expand with a lower-case e are different functions, and if you are using variables, capital X and lower-case x are different variables. The names of most built-in functions in Mathematica start with a capital letter.

The next principle is that function arguments are enclosed in square brackets.

If a function has more than one argument, the arguments are separated by commas, which is the same as in other computer languages and in traditional mathematical notation.
This use of square brackets, however, is a departure from traditional mathematical notation. This is done because traditional mathematical notation is ambiguous.

For example, y followed by 1+x in parentheses, in traditional mathematical notation, such as you might find in a mathematics book, sometimes means a function y evaluated at 1+x, and sometimes means y multiplied by 1+x.
This sort of ambiguity is not acceptable on computers. The computer needs to decide exactly what each input means. It is usually not a good idea to enter an input and hope that the computer will guess what was intended.
There are several ways to resolve this problem, and the way that is used in Mathematica is that, in Mathematica, y followed by 1+x in parentheses always means y multipled by 1+x, and, in Mathematica, y followed by 1+x enclosed in square brackets always means a function y evaluated at 1+x.

The last principle is that special notations are available for many common inputs.

For example, the plus sign in x+y indicates addition.

The carat characters in x carat y indicates an exponent, and so forth.

Just to clarify what is meant by a special notation the input 2+2 with a plus sign

2+2

can also be entered using a function called Plus with a capital P and with square brackets and a comma separating the arguments. So the plus sign is a special notation for the Plus function.

Plus[2,2]

Similarly, products can be entered by putting factors next to each other

2(3+4)

or by using the Times function, so putting factors next to each other is a special notation for the Times function.
You can in fact enter all of your Mathematica input using nothing but letters, numbers, commas, and square brackets. Some of these special notations, though, like the plus sign, are so convenient that almost no one would use the Plus function and an open bracket followed by 2 comma two and a closing bracket rather than entering 2+2, but there are lots of other special notations that you may encounter as you learn more about Mathematica where you can decide for yourself if you want to use these notations or if you would rather just spell out the name of the function.
Some people like these compact notations and some people don't. It doesn't make any difference to Mathematica. These notations are only provided for convenience. Deciding whether to use a special notation or two write out the name of the function in any given situation is a matter of personal preference.

Times[2,Plus[3,4]]

For many functions, however, there is no special notation.

Some typical inputs

For example, here is the input for computing the cosine of 1.6.

Cos[1.6]

Here is a function called Factor applied to a simple polynomial. The polynomial is entered using familiar notations for arithemtic and the factor function is entered by giving the name of the function followed by square brackets that enclose the argument of the function.
This example is typical of most Mathematica inputs, where some of the input is entered using special notations, and part of the input is entered using square brackets and spelling out the names of each function.

Factor[2+3x+x^2]

Here is a function with two arguments. This is the Solve function. The first argument is the equation and the second argument is the variable.
Again this input follows the same pattern, the name of the function, followed by square brackets that enclose the arguments of the function. The first argument here is an equation, here entered using a special notation involving a double equal sign, which I will describe in a moment, then a comma to separate the arguments, and then the variable.
The output here includes other special notations, these curly braces and the arrows, all of which can also be used in input.
Although Mathematica understands lots of special notations, there are really only a few notations that are very common.

Solve[x^2+5==1,x]

This list shows most of the special notations that are commonly used in Mathematica input and output.
The notations for arithmetic have already been discussed.
The notation for an equation is this notation with the double equal sign between the left and right sides of the equation.
The notation for an assignment uses a single equal sign.  I will explain in a moment what assignments are and how they work.
The notatio nfor a list is this notation with curly braces, which was used in the result from Solve.
The notation for picking out parts of lists, or parts of any expression, uses double square brackets. This notation is used frequently in matrix calculations such as for picking out elements of vectors or matrices.
Also used in the result from Solve was the notatio nfor replacement rules, which uses this arrow, which is entered as a dash followed by a greater-than character.
And finally, the notation for making substitution using a replacement rule is this input with a forward slash character followed by a period.
The notations for arithmetic have already been discussed, so we can move on to a few comments about equations.

Some common notations

Equations can be entered by giving a double = sign between the right and left sides of the equation.

Equations

Equations can be entered using a double = sign between the two sides of the equation.

For example, to enter an equation you enter the left side of the equation, then two equal signs, and then the right side of the equation. [click to evaluate] This equation just evaluates to itself. To get more interesting results you have to do something to the equation, such as solving it for a variable.

1+2x==5

This solves the equation 1+2x==5 for the variable x.

Solve[1+2x==5,x]

An input with one equal sign rather than two is an assignment.  Assignments are used to assign values to variables.

Assignments

Assignments are used to assign values to variables.

For example, this input assigns 5 as the value of a variable x.

x=5

After this assignment, x will be replaced by 5 whenever x appears in input. For example, if you evaluate x, the result is 5

x

And if you evaluate an expression that contains x, the x's will be replaced by 5 and Mathematica will work out the result.

2x+x y

One very useful feature related to assignments is that you can enter a question mark and the name of the variable and get a list of all of the things that are assigned to that variable. In this example this tells us that x has been assigned the value 5. This is a useful way to check up whether or not a value has been assigned to something or whether a value got assigned as you had intended. You don't need to be concerned for now that this Global`x notation is all about. Here it basically just means that this is a variable that was entered by you rather than a function that was built in to Mathematica.

?x

Be careful not to enter an assignment when you mean to enter an equation. [click to evaluate] For example, this calculation fails because x is replaced by 5 and the Solve function won't let you use a number like 5 as a variable.

Solve[x=5,x]

To avoid problems like this associated with variables that have values it is often a good idea to clear assigned values after you no longer need them. You can do this using a function called Clear. Clear[x] clears assigned values for x.

Clear[x]

After that, x will just evaluate to x.

x

2x+x y

Another common and important notation is this notation for lists. Lists are used throughout Mathematica for a wide range of purposes.  Lists are more common than any other type of expression in most Mathematica sessions. Lists are entered and displayed as a sequence of elements separated by commas and enclosed in curly braces.

Lists

Lists are entered and displayed as a sequence of elements enclosed in curly braces.

For example, here is a list of numbers.

We've already seen lists used in the output of Solve. The result from Solve is a list, and in fact the elements of that list are also lists. The replacement rules inside of these inner lists will be discussed in a moment.

Solve[x^2+1==5,x]

Lists are also used in the input to Solve. Here is an example showing the use of Solve to solve two equations for two variables.  Instead of a single equation, the first argument in Solve is a list with two equations, and instead of a single variable, the second argument in Solve is a list with two variables.

Solve[{y-2x==0,2x==8},{x,y}]

Lists are used in the input to other functions too. Here is an input to Plot, where the name of the function is Plot, the first argument is the function to plot, and the second argument is a list that gives the variable of the plot and the range of that variable.  This input plots a cubic polynomial for a variable x ranging from -3 to 3.

Plot[x^3-4x+6,{x,-3,3}]

Another common notation is the notation for picking out parts of expressions. The function that is used for picking out parts of expressions is called the Part function.

Parts

You can pick out parts of expressions using the Part function.

For example, this input picks out the second element, or the second part, of the list {x,y,z}, which is just the symbol y.

Part[{x,y,z},2]

Parts of expressions are used frequently when working with matrices. For example, here is an assignment that assigns a list of numbers as the value of a variable called data.

data={2.3,5.7,6.8,7.1,9.3}

This picks out the third element in the data.

Part[data,3]

This type of operation is so common that there is a special notation for it, which is the double square bracket notation mentioned earlier. [click to evaluate] There will be a few more examples of this later in this session in the segment on vectors and matrices.

data[[3]]

Now that we've talked lists and brackets and parentheses it seems useful to make a short digression to compare these four kinds of bracketing. There isn't any new information here, so this is just a review of things that have already been covered.
What I wanted to point out here in particular is that the uses of parentheses and brackets and curly braces listed here are the exclusive uses of these things. That is, parentheses are used for grouping in arithmetic and nothing else is used for grouping in arithmetic, and curly braces are used for lists and are not used for anything else. This is occasionally a source of trouble.

The four kinds of bracketing

For example, this is probably a nonsense input where it may be that whoever entered this (in this case it was me), thought that square brackets could be used for grouping. Instead, a literal reading of this input is a function named 2 evaluated at 3+4. Evaluating a function at 3+4 is not unusual, but using a number as the name of a function is probably an error.

2[3+4]

This input seems to work a little bit better, but this may or may not be what was intended. This input is 2 multipled by a list. Multiplying a list by a number is a reasonable thing to do, and what happens is that the multiplication gets threaded over the list, and 2 is multiplied by each element in the list, so the result is a list.

2{3+4}

Neither of these inputs is equivalent to this input, however, where parentheses are used for arithmetic grouping, and the result is a number, rather than a list that contains a number.
People who have done a lot of C programming (this includes me) are sometimes tempted to use curly braces for block structuring, which isn't the way that curly braces are used in Mathematica either. You don't enclose the body of a do-loop or a for-loop in curly braces, for example.
Basically the Mathematica use of these things is the ultimate in simplicity. Parentheses are used for arithmetic grouping and are not used for anything else, single square brackets are used for enclosing function arguments and are not used for anything else, and so forth, and after that there aren't really any problems.

2(3+4)

You can enter replacement rules by giving the left side of the rule followed by a dash followed by  a greater than character followed by the right side of the rule.

Replacement rules

Replacement rules can be entered using - followed by >.

For example, here is a replacement rule.
You may have noticed or if you look closely that when this expression was entered Mathematica took the dash followed by a greater than character and automatically replaced it by something, which is this arrow that you see here. This was done because Mathematica happens to have a special character for this arrow, and it decided in this example to use that character to improve the appearance of the input. It has not effect on functionality, so it isn't important in that respect.  It's just a small change in appearance.

We've already seen replacement rules used in the output to Solve to represent results.

Solve[x==5,x]

Replacement rules can also be used to make replacements. One of the functions that is used to apply replacements is called ReplaceAll. This input says to replace all of the x's by 5 in the expression 2x+x y.

ReplaceAll[2x+x y,x->5]

This type of operation is so common that there is a special notation for it. The special notation for ReplaceAll is this notation with the forward slash followed by a period or dot.
So reading this input, expression, slash-dot, rule, means to apply the rule to the expression.

2x+x y/.x->5

As a demonstration of all of these notations, here is an example showing the use of results from the Solve function.

Using results returned as rules

Replacement rules are used in the output of Solve.

The result from Solve is a list of solutions, and each solution is a list of rules. This equation has two solutions, so the result from Solve is a list with two elements. Each element is a solution represented as a list of rules. Since there is only one variable in this examle, each of those inner lists has only one rule.
The solution here has been assigned as the value of a variable called solution.

solution=Solve[x^2+1==5,x]

This picks out the first solution, using the double-square-bracket notationfor the part function.

solution[[1]]

This picks out the second solution.

solution[[2]]

One way to check this solution is to subtract the two sides of the equation, substitute the solution, and see if the result is zero. Subtracting the two sides of the equation in this example gives x^2+1-5. This input substitutes the value of x from the first solution in to that expression. The result is zero, so the solution is correct.

x^2+1-5/.solution[[1]]

Similarly, this substitutes the second solution into the difference between the two sides of the equation.

x^2+1-5/.solution[[2]]

Having covered a collection of basic notations I would like to mention a topic which is arguably rather more basic which is the names that you can use for variables. Essentially the name of a variable can include any notation that doesn't already have some other meaning.

Names of variables

Valid names for variables:

You can also use special characters in the names of variables. Capitalization can be used to separate words in a long variable name.

Here are some examples of invalid variables names. The first three names are invalid because they contain characters that already have some other meaning, and the last input starts with a number, so this is a product rather than a single variable name.

These variables names are not valid

We've gone through a long list of details so it seems useful to stop for a quick review of the basic principles of Mathematica input.
Mathematica is case-sensitive, function arguments are enclosed in square brackets, and special notations are available for many common inputs. And here is a list of the special notations that have been mentioned so far.
If you think you might be using these notations and would like to memorize them, you could try writing them down on a piece of paper and keeping that piece of paper near your computer.  There are perhaps a dozen other notations that are also used frequently, and that you may also want to memorize if you find yourself using them, but the list of special notations that you are likely to use often enough to justify memorizing them is not very long.

Review

Now I'd like to move on to a brief Tour of built-in functions. This is a short survey of some of the things that you can do without doing any programming, just by finding the right function and typing in your input.

Introduction to Mathematica

I have organized this tour into numerical operations, symbolic operations, operations with vectors and matrices, which includes both symbolic and numerical operations, plotting and graphics, and operations involving external files and programs.

Built-in functions in Mathematica

Numerical operations

Symbolic operations

Operations with vectors and matrices

Plotting and graphics

Operations involving external files and programs

One the subject of numerical operations, one feature of Mathematica that is different than, say, a typical pocket calculator, is that numbers in Mathematica can be exact or inexact.

Exact and inexact numbers

An inexact number is a number like 3.14159 with a decimal point, that is specified by giving some finite number of digits of the number.

An exact number is a number like an integer

or a fraction, that is specified by effectively giving all of the digits of the number.

Symbolic constants like Pi are also exact numerical quantities.

A general principle of Mathematica is that, except in functions that are obviously programmed to do otherwise, exact inputs give exact results, and inexact inputs give inexact results. For example, Sqrt[8] gives an exact result in terms of Sqrt[2].

Sqrt[8]

Square root of the inexact number 8.0 gives an inexact result.

Sqrt[8.0]

An exact input like Cos[1] just evaluates to Cos[1], because Cos[1] doesn't compute out to anything other than Cos[1].

Cos[1]

There are several ways to get an inexact approximation for Cos[1], one of which is to start out with inexact inputs.

Cos[1.0]

Another method is to use the N function, used here to compute an inexact approximation for Cos[1].

N[Cos[1]]

Here is an example showing the use of the N function to compute the first 150 digits of Cos[1].  The optional second argument of the N function specifies the number of digits to compute. The default is to use the precision provided by the hardware of your computer, which is about 16 digits on most computers.

N[Cos[1],150]

Mathematica includes an enormous collection of mathematical functions. It includes, for example, all of the basic trigonometric and inverse trigonometric functions.

Mathematical functions

({{Cos, Sin, Tan}, {Sec, Csc, Cot}, {ArcCos, ArcSin, ArcTan}, {ArcSec, ArcCsc, ArcCot}})

Notice the naming conventions for these functions.  Arccosine, for example, is spelled ArcCos with a capital A and a capital C.

ArcCos[0.5]

And beyond trigonometric functions there are hyperbolic functions and functions that you might find on a scientific pocket calculator and hundreds of other functions that come up in statistics and mathematical physics and other applications.

Mathematical functions

({{Cosh, Sinh, Log}, {Exp, Erf, EulerPhi}, {LegendreP, Zeta, FresnelC}, {JacobiSN, EllipticE, MathieuC}})

Some of these functions may seem exotic if you've never seen them before, but many of them at least are really fairly common. For example, EllipticE is the solution to this simple integral.

result = (∫_0^1)(Sqrt[ 2 - 
                Sin[x]^2]) \[DifferentialD]x

And of course if you would rather have a number for this result, you can use the N function to compute a numerical approximation for EllipticE.

N[result]

Mathematica includes all of the basic functions from numerical computation, like functions for numerical root finding, numerical minimization, numerical integration, and numerical solution of differential equations.

Numerical calculations

({{FindRoot, FindMinimum}, {NIntegrate, NDSolve}, {NonlinearFit, NProduct}, {NSum, Interpolation}})

Here is an example of a numerical integral. The name of the function is NIntegrate, the first argument is the integrand, then a comma, and the second argument is a list giving the variable of integration and the range of that variable.

NIntegrate[Cos[x]Exp[-x^2],{x,0,Infinity}]

Here is an example compute a root of an equation. The name of the function is FindRoot, the first argument gives the equation to solve, and the second argument gives the variable and a starting value for that variable. The solution is returned as a list of rules, as in the result from Solve.

FindRoot[x^2==3,{x,1}]

In addition to the documentation that you can find in the book for these functions you can get quick information you fingertips which will at least provide the syntax for these functions using ?symbol as I used a few minutes ago.  Here is the information that you get when you enter ?FindRoot.

?FindRoot

Mathematica includes a large collection of functions for symbolic operations -- symbolic integration, symbolic differentiation, limits, series, solving equations, and underlying operations on polynomials.

Symbolic calculations

({{Integrate, Limit}, {D, Series}, {Derivative, Solve}, {DSolve, Simplify}, {Expand, Apart}, {Together, Factor}, {Coefficient, Collect}, {FourierTransform, LaplaceTransform}, {GroebnerBasis, PolynomialReduce}})

Here is a symbolic derivative.  The function here is D, the first argument is the function to be differentiated, and the second argument is the variable.

D[x Cos[x],x]

Here is a symbolic integral using the Integrate function.  The first argument is the integrand and the second argument is a list giving the variable of integration and the range of that variable.

Integrate[Exp[-x^2]/Sqrt[Pi],{x,1,Infinity}]

A very important topic both for numerical operations and symbolic operations is linear algebra. In Mathematica, vectors are represented using lists, and matrices are represented as a list of lists.

Vectors and matrices

A vector is a list of elements.

A matrix is a list of lists.

For example, here is a vector in which all of the elements are numbers.

{1.7,2.3,4.5,7.9}

Here is a 2 by 2 matrix, and again all of the elements are numbers. This input assigns this matrix as the value of m. I did this assignment so I could use this matrix in the next few examples.

m={{2.3,5.1},{4.8,3.1}}

You can display this matrix in a more familiar notation using the MatrixForm function. You can also enter the matrix in this form. I will describe later how to do that.

MatrixForm[m]

Here are some basic matrix operations. This uses the part function, entered using double square brackets, to pick ou the first row of the matrix.

m[[1]]

This picks out the first element in the first row of the matrix.

m[[1,1]]

You can use the word All to pick out all of the rows in a matrix. This input picks out the first element from all of the rows, so this is the first column of the matrix. In other matrix manipulation systems like Matlab there is often a notation like this.

m[[All,1]]

This input computes the dot product of a matrix and a vector. The dot product is entered by putting a dot or a period between the factors.

m.{2,3}

Mathematica includes a solid collection of functions for operations on matrices, such as computing eigenvalues and eigenvalues, various matrix decompositions, and so forth.

Matrix functions

({{Eigenvalues, Eigenvectors}, {Eigensystem, SchurDecomposition}, {LinearSolve, QRDecomposition}, {Det, CholeskyDecomposition}, {MatrixExp, LUDecomposition}, {MatrixPower, LUBackSubstitution}, {Tr, SingularValues}, {Transpose, JordanDecomposition}, {Inverse, PseudoInverse}})

Here is an input that uses the Eigenvalues function to compute the eigenvalues of a 2 by 2 matrix.

Eigenvalues[{{1.7,2.3},{4.8,3.1}}]

All of these operations or at least most of them also work on symbolic matrices.  This input computes the eigenvalues of a symbolic matrix.

Eigenvalues[{{x1,x2},{x3,x4}}]

Now I'd like to move on to some examples of plotting. Here is a list of some of the functions in Mathematica for plotting functions, as opposed to plotting data.

Plotting

({{Plot, Plot3D}, {ContourPlot, DensityPlot}, {ParametricPlot, ParametricPlot3D}, {LogPlot, LogLinearPlot}, {LogLogPlot, PolarPlot}})

Here is a basic example showing the use of the Plot function. The name of the function is Plot, then a square bracket, then the function to plot, a comma, and the second argument is a list that gives the variable of the plot and the range of that variable.
Notice that this is essentially the same syntax that was used in Integrate and in the numerical integration function NIntegrate. This illustrates a very nice feature of Mathematica which is that once you figure out how to use one part of the program you can usually use the same approach to use other parts of the program.

Plot[Sin[x],{x,0,2Pi}]

Here is a plot of a surface using the Plot3D function. The first argument is the function to plot, the second argument is a list that specifies that one of the independent variables is x and gives the range of that variable, and the third argument is a list that specifies that the other variable is y and gives the range of that variable.

Plot3D[Sin[x y],{x,0,4},{y,0,4}]

FrontEndExecute[
      FrontEndToken[SlideShow`nb, "ScrollLineUp"]]

As I just mentioned there are corresponding functions for plotting data. Here is a list showing some of those functions.

Plotting data

({{ListPlot, ListPlot3D}, {ListContourPlot, ListDensityPlot}, {LogListPlot, LogLogListPlot}, {LogLinearListPlot, Histogram}, {BarChart, MultipleListPlot}, {PieChart, ErrorListPlot}})

Here is an example showing the use of the ListPlot function to plot a list of data points. The points are specified as coordinate pairs. A coordinate pair in Mathematica is just a list with two numbers.

ListPlot[{{1,1},{2,2},{4,3},{5,4},{6,2},{7,5}}]

It might be nice to have bigger points in this plot. This can be done in ListPlot by adding an option. An option is just a rule. This example shows the effect of adding the option PlotStyle->PointSize[0.03]. There are many features of plots, and in fact many details of many Mathematica functions, that are controlled using options.

NotebookFind[SlideShow`nb, "]"]; 
    SelectionMove[SlideShow`nb, Before, Character]; 
    Scan[(NotebookWrite[SlideShow`nb, #]; ShortPause) &, 
      Characters[",PlotStyle->PointSize[0.025]"]]; 
    SlideShow`$EvaluationToggle = True;

Here is another option, called the PlotJoined option, that controls whether the data are shown as dots or by connecting the data points with straight lines.

NotebookFind[SlideShow`nb, "PlotStyle"]; 
    FrontEndExecute[FrontEndToken[SlideShow`nb, "ExpandSelection"]]; 
    Scan[(NotebookWrite[SlideShow`nb, #]; ShortPause) &, 
      Characters["PlotJoined->True"]]; 
    SlideShow`$EvaluationToggle = True;

And for the last topic in this tour, you can read data in to Mathematica from a file or write data out to files or communicate with other programs.  Here are some of the functions for reading and writing data in files.

Reading and writing files

({{Read, Write}, {ReadList, OpenWrite}, {OpenRead, OpenAppend}, {Save, Get}, {Import, Export}})

Here is an example of using the Export function to write a table of numbers to a file.

Export["file",{{1,2},{3,4}},"Table"]

This exclamation point exclamation point notation can be used to dump the contents of a file to the screen. You probably would't use this very often, especially for large files, but it is useful in demonstrations. This shows the file that was written out using Export.

!!file

This reads the file back in using Import.

Import["file","Table"]

A separate way of setting up interaction with the rest of your computer, in addition to exchanging information through files, is to set up a communication channel so that two programs can send information back and forth dynamically. In Mathematica this is done using MathLink, which provides an interprocess communication protocol and interprocess communication services for exchanging structured information between programs.
You can use MathLink when you want to call Mathematica from another program or when you want to call a program that you've already got from Mathematica.
One demonstration of MathLink is everything that I've been doing so far. Mathematica is composed of several components, most notably the component that manages the editor and the display that you see on the computer screen, and the component that does all of the calculations, and those two components exchange information through MathLink.

MathLink

MathLink is a general interprocess communication system

You can use MathLink to connect Mathematica with other programs

Communication within Mathematica uses MathLink

After that short tour of doing calculations with Mathematica I would like to turn now to a few comments about the interface to Mathematica, with a few comments about notebooks and typesetting.

Introduction to Mathematica

As mentioned earlier, the files that you edit using Mathematica are called notebooks.

Notebooks

One important characteristic of notebooks is that they are portable between computers.  Notebooks are stored as ordinary text files on your computer, so you can exchange them as plain text files using email, for example. Notebooks can contain information that is not portable, such as if they use fonts that are not available on other computers, but all of the Mathematica-specific content of notebooks is portable between computers.

One concept that is essential to undertanding notebooks is the notion of a cell. Notebooks are organized as a list of cells. A few examples in a moment will serve to illustrate what a cell is.

Cells can have different styles.  Some of the more common styles are input cells, which are the cells that contain your input, output cells, which are the cells in which Mathematica displays your results, graphics cells, which are used for graphical images, and text cells, which you can use to put comments and explanations and discussions in your notebooks.

One of the more useful features of cells, which I will demonstrate in a moment, is that cells can contain other cells, which means that you can use the cell structure of a notebook to organize all of the information in a notebook in a hierarchical format like in a book with sections and subsections and so forth.

I'd like to work through a short demonstration of cells and cell styles. The points to be made here are about automatic cells styles like input cells, output cells, and graphics cells, where the cell style is chosen by Mathematica, how to set cell styles, such as when you want text cells or section cells, grouping of cells, and opening and closing cell groups.
[Click the demo button to step through a typical demonstration. This demonstration is more effective if done live.]

Cells and cell styles

Cell styles chosen by Mathematica

Setting cell styles

Cell grouping

Opening and closing cells

start demo

The first cells styles to notice are input cells and output cells. When you enter your input, Mathematica creates an input cell for your input. Notice the bracket near the right side of the screen. This bracket is called a cell bracket.  The cell bracket encloses the contents of the cell. When you evaluate this input, Mathematica generates an output cell right below the input cell. The input cell and the output cell are grouped together as indicated by the outermost cell bracket.  This outermost cell bracket shows an example of a cell that contains other cells.

Null

SlideShow`new = 
        NotebookCreate[Magnification -> 2, 
          ImageSize -> {180, 180}];

Scan[(NotebookWrite[SlideShow`new, #]; SlideShow`ShortPause) &, 
        Characters["2+2"]];

FrontEndExecute[
        FrontEndToken[SlideShow`new, "EvaluateCells"]];

Another common type of cell is a graphics cell. Here is an input that generates a plot. The input goes into an input cell, the image goes into a graphics cell, the output goes into an output cell, and all three cells are grouped together as indicated by this outermost cell bracket.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SetSelectedNotebook[SlideShow`new]; 
    Scan[(NotebookWrite[SlideShow`new, #]; SlideShow`ShortPause) &, 
      Characters["Plot[Cos[x],{x,0,2π}]"]];

FrontEndExecute[
        FrontEndToken[SlideShow`new, "EvaluateCells"]];

So far all of the cell styles have been chosen automatically by Mathematica. To get other cells styles you need to change the cell style yourself. You can do that by selecting the cell bracket and choosing the desired style from the Style submenu of the Format menu.
To demonstrate that I will enter a new cell just above the cell with the Plot command. Notice that when I move the mouse through the notebook the mouse pointer changes shape from a vertical bar, indicating a place where I could edit something, to a horizontal bar, when the mouse is between cells, indicating a place where I could enter a new cell. To create a new cell in a particular place, I click the mouse when the mouse pointer is a horizontal bar. When I do this, I see a horizontal line, which is a cell insertion point, indicating where the new cell will appear.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SetSelectedNotebook[SlideShow`new];

SelectionMove[SlideShow`new, Previous, CellGroup]; 
    SelectionMove[SlideShow`new, Before, CellGroup];

Now when I start typing I get an input cell.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SetSelectedNotebook[SlideShow`new]; 
    Scan[(NotebookWrite[SlideShow`new, #]; SlideShow`ShortPause) &, 
      Characters["Here is a plot of the cosine function."]];

To change the cell style to text style I select the cell by clicking the mouse pointer on the cell bracket for this cell, and select text style from the Style submenu of the Format menu. This changes the font and other characteristics of this cell so that it is visually distinguished from the other cells in this notebook.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SetSelectedNotebook[SlideShow`new];

SelectionMove[SlideShow`new, All, Cell];

FrontEndExecute[
        FrontEndToken[SlideShow`new, "Style", "Text"]];

Continuing in this manner leads to a notebook that looks like this one, with inputs, graphics, and explanatory text.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SetSelectedNotebook[SlideShow`new]; 
    SelectionMove[SlideShow`new, Before, Notebook]; 
    NotebookWrite[SlideShow`new, Cell["This is a sum.", "Text"]]; 
    SelectionMove[SlideShow`new, Next, CellGroup]; 
    SelectionMove[SlideShow`new, After, CellGroup]; 
    Do[SelectionMove[SlideShow`source, Next, Cell]; 
      FrontEndExecute[{FrontEndToken[SlideShow`source, "Copy"], 
          FrontEndToken[SlideShow`new, "Paste"]}], {6}]

Input using character names and aliases

π ∫x \[DifferentialD]x

Input using control sequences

(Sqrt[((x^2)/(x + 1))])

Input using a palette

(({{1, 2, 5}, {3, 4, 6}, {7, 8, 9}}))

FrontEndExecute[
      FrontEndToken[SlideShow`new, "ScrollNotebookStart"]]

Do[FrontEndExecute[
        FrontEndToken[SlideShow`new, "ScrollLineDown"]], {8}]

Do[FrontEndExecute[
        FrontEndToken[SlideShow`new, "ScrollLineDown"]], {8}]

Do[FrontEndExecute[
        FrontEndToken[SlideShow`new, "ScrollLineDown"]], {8}]

This notebook can be organized into sections by adding section cells. These cells are added much like adding text cells, except that instead of setting the cell style to Text I will set the cell style to Section.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SetSelectedNotebook[SlideShow`new]; 
    SelectionMove[SlideShow`new, Before, Notebook];

NotebookWrite[SlideShow`new, "First section"]

SelectionMove[SlideShow`new, All, Cell];

FrontEndExecute[
        FrontEndToken[
          SlideShow`new, "Style", "Section"]];

SelectionMove[SlideShow`new, After, Notebook]; 
    SelectionMove[SlideShow`new, Previous, Cell, 4]; 
    SelectionMove[SlideShow`new, Before, Cell];

NotebookWrite[SlideShow`new, "Second section"]

SelectionMove[SlideShow`new, All, Cell];

FrontEndExecute[
        FrontEndToken[
          SlideShow`new, "Style", "Section"]];

If you now look at the outer cell brackets, you will see that all of the cells have been grouped into two cell groups, each starting with a section cell.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SetSelectedNotebook[SlideShow`new]; 
    SelectionMove[SlideShow`new, Before, Notebook];

Do[FrontEndExecute[
        FrontEndToken[SlideShow`new, "ScrollLineDown"]], {10}]

Do[FrontEndExecute[
        FrontEndToken[SlideShow`new, "ScrollLineDown"]], {10}]

Do[FrontEndExecute[
        FrontEndToken[SlideShow`new, "ScrollLineDown"]], {10}]

One of the more useful features of cell groups, and one of the more useful features of notebooks in general, is that you can open and close these cell groups. You can close a cell group by double-clicking on the cell bracket, and you can open a closed cell group by double-clicking on the corresponding cell bracket.
For example if you are only working on the second section, you could close up the first section, and to see an outline of the notebook, you could close up both sections.
To reopen the a group, double-click on the corresponding cell bracket.

SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

SetSelectedNotebook[SlideShow`new]; 
    SelectionMove[SlideShow`new, Before, Notebook];

SelectionMove[SlideShow`new, Next, CellGroup]; 
    FrontEndExecute[
      FrontEndToken[SlideShow`new, "OpenCloseGroup"]];

SelectionMove[SlideShow`new, Next, CellGroup]; 
    FrontEndExecute[
      FrontEndToken[SlideShow`new, "OpenCloseGroup"]];

FrontEndExecute[
        FrontEndToken[SlideShow`new, "OpenCloseGroup"]];

NotebookClose[SlideShow`new]; SetSelectedNotebook[SlideShow`notes]; 
    SetSelectedNotebook[SlideShow`nb];

end demo

Although I mostly talked earlier about entering input using notation involving functions names and square brackets, it is also possible to enter your input and display your results in typeset formats that more closely approximate traditional mathematics or at least to make your inputs and outputs more readable.

Typesetting

The Mathematica notebook interface is a typeset editor

A typeset editor means that you can edit output as well as input. The output is not dead on the screen as with a typeset formatter. You can copy and paste and modify and evaluate everything that you see, just as you might do with paper and pencil, except the formatting is typeset quality and behind your work is the full computational power of Mathematica.

You can edit inputs and outputs

As a demonstration I will work through three examples illustrating three basic ways of entering typeset input -- input using special characters, input using control sequences, which means input using the control key, and input using a palette.

Typesetting examples

Input using special characters

Input using control sequences

Input using a palette

First, input using special characters. The example here is this integral using the integral sign, which is equivalent to this input using the Integrate function.

Typesetting examples

Input using special characters

start demo

There several ways to enter any special character, but the way that I find most convenient for entering the Greek letter π is to use the character alias p, which is used by typing the escape key, followed by a p, followed by the escape key.

NotebookWrite[SlideShow`nb, ""];

NotebookWrite[SlideShow`nb, "p"];

NotebookWrite[SlideShow`nb, ""];

The alias for the integral sign is int, so the integral sign can be entered by typing escape, int, escape.

NotebookWrite[SlideShow`nb, ""];

NotebookWrite[SlideShow`nb, "int"];

NotebookWrite[SlideShow`nb, ""];

The variable x is just entered x.

NotebookWrite[SlideShow`nb, "x"];

The alias for the differential d is dd, so the next character is escape dd escape.

NotebookWrite[SlideShow`nb, ""];

NotebookWrite[SlideShow`nb, "dd"];

NotebookWrite[SlideShow`nb, ""];

And finally another x. [click to evaluate] This typeset input can then be evaluated just like the input using the Integrate function.

NotebookWrite[SlideShow`nb, "x"]; 
    SlideShow`$EvaluationToggle = True;

end demo

The next example is this expression which can be entered using control sequences, which means using the control key.  This  input with traditional square root notation is equivalent to this input with the Sqrt function.

Typesetting examples

Input using control sequences

start demo

To get started, the square root sign can be entered using control-2. This leaves an empty box under the square root sign, which is where my next input will be placed.

FrontEndExecute[
        FrontEndToken[SlideShow`nb, "Radical"]];

Now I enter the x, and the command to get the superscript is control-6, which you can remember because the 6 key is the key with the carat character. So shift 6 gives a carat character which is used for entering powers, and control 6 gives a typeset power.

NotebookWrite[SlideShow`nb, "x"];

FrontEndExecute[
        FrontEndToken[SlideShow`nb, "Superscript"]];

NotebookWrite[SlideShow`nb, "2"];

To get out of the superscript and back to the baseline I type control-space.

SelectionMove[SlideShow`nb, After, Expression]

To get a fraction, I type control and a forward slash, which can be remembered because a forward slash is also used to enter division.

FrontEndExecute[
        FrontEndToken[SlideShow`nb, "Fraction"]];

Then type in the denominator.

NotebookWrite[SlideShow`nb, "x+1"];

end demo

And finally as an illustration of input using a palette, I want to show how to use a palette to enter this matrix. The typeset matrix is equivalent to this input using lists.

Typesetting examples

Input using control sequences

The basic input palette which comes up by default is used just by clicking on buttons in the palette. When you do that, the corresponding template appears in your notebook.  For example, if you click on this button with the two by two matrix, you get a template for a two by two matrix in your notebook.

SelectionMove[SlideShow`source, Next, Cell]; 
    FrontEndExecute[{FrontEndToken[SlideShow`source, "Copy"], 
        FrontEndToken[SlideShow`nb, "Paste"]}]; 
    SelectionMove[SlideShow`nb, Before, Cell]; 
    NotebookFind[SlideShow`nb, "\[Placeholder]"];

(({{\[Placeholder], \[Placeholder]}, {\[Placeholder], \[Placeholder]}}))

You can enter matrix elements by typing in the element, and skip to the next element using the tab key, which is the same as in spreadsheets and other programs.

NotebookWrite[SlideShow`nb, 1]

FrontEndExecute[FrontEndToken[SlideShow`nb, "Tab"]]

NotebookWrite[SlideShow`nb, 2]

FrontEndExecute[FrontEndToken[SlideShow`nb, "Tab"]]

NotebookWrite[SlideShow`nb, 3]

FrontEndExecute[FrontEndToken[SlideShow`nb, "Tab"]]

NotebookWrite[SlideShow`nb, 4]

You can add a row to this matrix by pressing control return, and you can add a column to the matrix using control comma.

FrontEndExecute[FrontEndToken[SlideShow`nb, "NewRow"]]

FrontEndExecute[
      FrontEndToken[SlideShow`nb, "NewColumn"]]

Then fill in the rest of the matrix.

NotebookWrite[SlideShow`nb, 5]

FrontEndExecute[FrontEndToken[SlideShow`nb, "Tab"]]

NotebookWrite[SlideShow`nb, 6]

FrontEndExecute[FrontEndToken[SlideShow`nb, "Tab"]]

NotebookWrite[SlideShow`nb, 7]

FrontEndExecute[FrontEndToken[SlideShow`nb, "Tab"]]

NotebookWrite[SlideShow`nb, 8]

FrontEndExecute[FrontEndToken[SlideShow`nb, "Tab"]]

NotebookWrite[SlideShow`nb, 9]

end demo

One last topic I would like to mention is programming. This is actually a very large topic, and five minutes of talking about it certainly won't make you into an expert programmer, but programming is such an important part of Mathematica that it seems worthwhile to at least mention it, even in an introduction. Programming is what distinguishes Mathematica from a fancy calculator. Programming is what enables you to extend Mathematica to do anything that you want.

Introduction to Mathematica

If you've used other programming languages you will probably be interested to know that Mathematica is implemented as an interpreted programming language, which means that you enter your commands and those commands are processed by a running copy of Mathematica. This is as opposed to a compiled language, which is typically the way that languages such as C and Fortran are implemented, where you type your program into a file and a compiler converts that file into a standalone program that can run independent of the compiler or anything other than the operating system of your computer. There are advantages and disadvantages of both ways of doing things that I don't want to get in to right here, so the only point to be remembered here is that you need a running copy of Mathematica to process your Mathematica programs.

Programming

Mathematica is implemented as an interpreted language

Input is processed by a running copy of Mathematica

Fortran, C, ..., are typically implemented as compiled languages

A compiler generates an executable program

There are many ways to organize programs all of which at some level amount to variants of the same thing, but there are nevertheless some recognizable differences, which I will describe here as procedural programing, programming with rules, and functional programming.

Programming styles

Procedural programming

Programming with rules

Functional programming

Procedural programming is the type of programming that most people learn first. Procedural programming means programming using commands like do-loops and if-statements and other functions collectively referred to as control structures that control which statements in a program will be executed and how many times and in what order. Control structures control the flow of execution through a program.  Procedural programming in Mathematica is supported by the functions shown here, like the Do, While, and For functions for loops, the If and Switch functions for conditional transfer of control, and so forth.

Procedural programming

({{Do, While, For}, {If, Switch, Which}, {Return, Break, Continue}, {Goto, Label, CompoundExpression}})

Here is a simple example of a procedural program. The semicolon in this program separates the two statements of the program. This program uses the If function. If the first argument of the If function evaluates to True, then the second argument is evaluated, and if that first argument evaluates to False then the third argument is evaluated. The If function is a control structure that controls which of two other statements will be executed.

x=22;
If[EvenQ[x],
  Print[x, " is even"],
  Print[x, " is not even"]]

In this program the EvenQ function is a simple function that returns True if the argument is even and false otherwise.

EvenQ[22]

EvenQ[23]

The Print function is a function that displays its argument in the notebook. The expression printed here is a string, which is entered as a sequence of characters enclosed in double quote marks.

Print["hello"]

Here is another procedural program, this time a loop that prints out the integers from 1 through 5. The function here is the Do function. This input evaluates the first argument of the Do function for k ranging from 1 to 5.

Do[Print[k],{k,1,5}]

Another programming style is programming with rules, which means programming by applying transformation rules to expressions. This includes assignments and definitions, since an assignment just sets up a transformation rule that is applied automatically by Mathematica.

Programming with rules

Programming with assignments, rules, and definitions

For example, evaluation of this assignment introduces a rule that replaces x by 5 whenever x occurs during evaluation.

x=5

2x+x y

You can achieve exactly the same effect by applying the transformation rule yourself, so an assignment is just a way of introducing a rule that is applied automatically.

Clear[x]

2x+x y/.x->5

You can also use assignments to define functions.

Defining functions

You can also use assignments to define functions

Here is an assignment that defines a function f that takes an argument x and evaluates to x Cos[x]. The left side of this assignment is a pattern that specifies the class of expressions for which this definition should be used. The underscore character on the left side of this assignment is a pattern that matches any expression, so this definition will apply to any function f called with one argument, and that argument can be anything.

f[x_]=x Cos[x]

After defining this function, the input f[3] will evaluate to 3 Cos[3].

f[3]

By combining function definitions you can build up complicated programs. For example, here is a definition for a function g.

g[p_]=p/(1+p)

When f[3] is used as the argument in g, both the definition of f and the definition of g are used.

g[f[3]]

Just as when defining variables, it is a reasonable practice to clear function definitions after you are through using them.

Clear[f,g]

One topic that you will probably come across fairly early in your Mathematica programming career is the distinction between delayed an immediate assignments. An easy way to see the difference and what the issues are is by looking at a simple example.

Delayed and immediate assignments

Suppose I define a function using Expand on the right side of the definition. [click to evaluate] After this definition, the definition of f is what results from expanding the right side of the assignment.

f[p_]=Expand[(1+p)^3]

If I use this rule with f[1+x], 1+x is inserted for p on the right side of that definition.

f[1+x]

Suppose however that I wanted the 1+x to be expanded out too. To get that effect, I don't want the Expand to be processed until after the rule is used and the value of the function argument is inserted into the right side of the definition. An easy way to get that effect in Mathematica is with what is called a delayed assignment, which here is entered using a colon-equal sign rather than an equal sign.

f[p_]:=Expand[(1+p)^3]

With this definition, f[1+x] expand out completely, because Expand on the right side of the definition isn't processed until after 1+x inserted for p.
There is nothing subtle or complicated about the distinction between delayed and immediate assignments, and the distinction isn't really fundamental part of the system. The basic answer to any question about when to use delayed assignments and when to use immediate assignments is to use immediate assignments whenever you want function arguments to be inserted into the right side of the definition after the right side of the definition is evaluated, and use delayed assignments if you want function arguments to be inserted into the right side of the definition before the right side of the definition is evaluated.
In other words, used immediate assignments when you want the first effect shown by these examples, and use delayed assignments when you want the second effect. In most practical cases the choice of obvious.

f[1+x]

Functional programming means programming by applying functions to the results of other functions. Since all programming in Mathematica is done using functions, there is a sense in which all programming in Mathematica is functional programming, but there is still a way of organizing programs that can be idenfied as functional programming.  Functional programming in Mathematica makes extensive use of functions like Map and Apply and the other functions in this list.

Functional programming

({{Map, Apply, Scan}, {MapAll, MapAt, Select}, {Cases, Through, Function}, {Thread, Inner, Outer}, {Throw, Catch, MapThread}})

Here is a functional program using the Select function to pick out the even numbers from a list. This input may be self-explanatory if you study it for a moment. The function here is select, the first argument is a list from which to select expressions, and the second argument is the test that specifies which expressions to select.

Select[{1,3,4,6,7,8,12},EvenQ]

Here is an example using the Apply function to add up the elements in a list. Applying the Plus function to this list turns the list into a sum, and Mathematica then evaluates that sum.

Apply[Plus,{1,3,4,6,7,8,12}]

This functional program is equivalent to the following procedural program.

SelectionMove[SlideShow`source, Next, Cell]; 
    FrontEndExecute[{FrontEndToken[SlideShow`source, "Copy"], 
        FrontEndToken[SlideShow`nb, "Paste"]}];

data={1,3,4,6,7,8,12};
result=0;
Do[
    result=result+data[[k]],
    {k, 1, Length[data]}
];
result

There is no general principle that says that any one way of organizing programs is better than any other way. Most good Mathematica progams use a mixture of programming styles, using whichever style is most natural or most efficient for a particular task. If you already know how to do procedural programming then you could start by learning how to do the same things in Mathematica, and then learn other programming functions in Mathematica as you go along or as the need arises.

SelectionMove[SlideShow`nb, Previous, Cell]; 
    FrontEndExecute[
      FrontEndToken[SlideShow`nb, "EvaluateCells"]]

And finally, I would like to describe some sources for more information, especially sources for information related to topics that were mentioned in this session.

Introduction to Mathematica

The most complete and authoritative source of information about Mathematica is The Mathematica Book, which is available both as a large printed book or as part of the online help system.
Another source of information is of course the online help system, which you access using the Help Browser. There are a couple of items in the Help Browser that I would like to mention as of particular interest when just getting started.

Sources for more information

Some things I would like to point out in the Help Browser are a section called Your first calculations which descibes basic input, a section on using the Help Browser, a section with step-by-step examples of entering typeset expressions, and a section called Tour of Mathematica.
You bring up the Help Browser by selecting Help Browser from the Help menu.
Your First Calculations is under Getting Started/Demos - [system] - Starting Out
Using the Help Browser is under Getting Started/Demos
2D expression input is under Other Information
Tour of Mathematica is under Mathematica Book

The Help Browser

start demo

HelpBrowserLookup["GettingStarted", "Your First Calculations \
(Windows)"]

HelpBrowserLookup["GettingStarted", "Using the Help \
Browser"]

HelpBrowserLookup["OtherInformation", ""]

HelpBrowserLookup["MainBook", "Tour of Mathematica"]

end demo

In addition to The Mathematica Book and the Help Browser, there are several other sources of information.
In the Wolfram Research web site you can find tutorials, examples, announcements, and information about products related to Mathematica.
There are also a few hundred books about Mathematica from introductory books to books about particular aspects of Mathematica of books about the use of Mathematica in various areas of application. You can find a list of books about Mathematica in the Wolfram Research web site.
And finally, additional training is available.  There is a list of independent trainers in the Wolfram Research web site, and you can find out about training offered by Wolfram Research by contacting Wolfram Research or by sending mail to either of these electronic mail addresses.

Sources for more information