Saturday, March 10, 2012

Beginners: Mathematica Front End, Kernel, and Notebooks

Front End and Kernel

There are two components to Mathematica: the Front End and the Kernel. Unless you decide to use a command-line (aka "text-based") interface at a terminal, you are using the graphical user interface (GUI) of Mathematica called the Front End. If you program in Mathematica, the Front End is also your programming environment. You will find the Front End to be a superior GUI and programming environment once you get used to it. However the part of Mathematica that does the computation you request through the Front End is called the Kernel. The Kernel can run on the same computer as the Front End or on remote computers.

Mathematica Notebooks 



Most often you work in a Mathematica Notebook (the filename ends in .nb). Think of a Notebook as an electronic laboratory notebook attached to a very powerful computer (the kernel). You can do almost anything you can think of in a Notebook, such as write text, mathematical formulae, a program, or even a paper, book or webpage. You can communicate with Mathematica's help files, which are in the Documentation Center, request information, perhaps on a function, to be displayed right in the notebook where you are working, or in a separate browser within the Mathematica environment. And you can communicate with the kernel and ask it to do a simple or enormously complicated computation, even if the kernel is located at a remote site.

The Mathematica Notebook consists of a hierarchy of nested cells. You select an entire cell by clicking it's bracket in the right margin. You select contents within a cell in the normal way. Within a cell, the insertion point is a prominent blinking vertical bar, while the cursor is a vertical bar with a capital and base (an "I-beam"). But note that between cells, the insertion point is a prominent horizontal bar running all the way across the notebook, while the cursor is a horizontal I-beam that disappears when not quite between the cells.

You will soon automatically notice whether a cell bracket\[LongDash]the vertical, terminated bar at the right of the cell\[LongDash]is denoted at the top by two small horizontal lines or a triangle. The two small lines indicate an open cell, and the triangle indicates a closed cell. To open the closed cell and view its content, double-click anywhere on the cell bracket. Likewise, in the left margin, open cells are indicated by an upward arrowhead (an angle bracket) and closed cells by a downward arrowhead, and you can toggle open or closed by clicking on the arrowhead.

Clicking Enter on the alphabetic keyboard is equivalent to Return, not Enter. Shift-Enter on the alphabetic keyboard and Enter on the numeric keypad (provided NumLock is on) are equivalent and tell Mathematica to evaluate the current cell if it is an input cell. What "evaluate" means is explicitly explained in Mathematica if you need to understand the details.

The first time you click Enter (in an input cell) after starting a Mathematica session, there is a delay while the Kernel is started and performs its evaluation of your request.

A Mathematica mantra is "Everything is an Expression," which means that the universal, unifying syntax of Mathematica is a normal form expression with a head and argument: head[argument]. Suffice it to say here that the Mathematica Notebooks are entirely rendered via expressions and every aspect of Notebooks are potentially under your control.

<Shift> + <Enter> causes Mathematica to evaluate the contents of the cell containing the input point of that you have selected by clicking its bracket. Remember that the selected cell may not be the last cell in your Notebook, but rather, if you have "skipped around" it is the last cell you have evaluated. Also critical is that the selected cell is processed in light of all previous evaluations, no matter in what order they appear in the notebook. You can always tell what the kernel has seen by the Input and Output line numbers. I.e., that last expression the kernel processed was sent to it in the cell with the highest line number.

You will find it convenient to not always move sequentially down a Notebook but rather to stay in one cell or group of cells, or to skip around a bit. But this will not work unless you pay attention to what the kernel has seen, often using line numbers. Sometimes it is easier to just clear your definitions are start from scratch than to figure out what the kernel has seen.

These mechanics will soon become second nature and you will fall in love with the Mathematica Notebook, your working document in the elegant, unique Mathematica graphical user interface (the "front end").


No comments:

Post a Comment