Mathematica® programming: an advanced introduction

Categories:

Recommended

Introduction

Mathematica is built on a small number of universal principles. Good understanding of these principles isa pre-requisite for understanding how to program in Mathematica. Here I will discuss them, but rather briefly. Excellent and in-depth discussion of them can be found in several places.

1.1 First principle: everything is an expression

The first principle states that every object dealt with by Mathematica, is an expression. Every Mathematica expression is either Atom, or a Normal Expression.

Atoms and the built-in AtomQ predicate

Atoms are numbers, symbols and strings, and numbers are further divided into Integers, Reals, Rationalsand Complex. All other objects are composite and are called Normal Expressions. It is always possible tocheck whether or not an expression is an atom or a composite, by acting on it with the built-in predicateAtomQ. For instance:

ClearAll@”Global‘*”D; 8AtomQ@xD, AtomQ@Sin@xDD, AtomQ@1 +I * 2D, AtomQ@2  3D< 8True, False, True, True<

1.1.2 Mathematica normal (composite) expressions

Every normal expression (composite) is built according to a universal pattern:

expr@el1, …, elnD

Here it is required that some symbol < expr > is present (it can itself be a normal expression, not necessarily an atom), as well as the single square brackets. Inside the square brackets, there can be zero, one or several comma-separated elements <el1>,…,<eln>. These elements themselves can be either atoms or normal expressions. In an expression Sin[x], <expr> is Sin, and there is a single element <x>, which is atom (as long as x is not defined as something else, but this already has to do with expression evaluationand will be discussed below). It is clear that an arbitrary Mathematica expression must have a tree-likestructure, with the branches being normal (sub)expressions and leaves being atoms.

Category:

Attribution

Leonid Shifrin. Mathematica® programming: an advanced introduction. http://www.mathprogramming-intro.org/

VP Flipbook Maker

Convert your work to digital flipbook with VP Online Flipbook Maker! You can also create a new one with the tool. Try it now!