Compile

Compile[, , ... , expr] creates a compiled function which evaluates expr assuming numerical values of the .

Compile[, , ... , expr] assumes that is of a type which matches .

Compile[, , , ... , expr] assumes that is a rank array of objects each of a type which matches .

Compile[vars, expr, , , ... ] assumes that subexpressions in expr which match are of types which match .

The types handled by Compile are:

Nested lists given as input to a compiled function must be full arrays of numbers.

Compile handles numerical functions, matrix operations, procedural programming constructs, list manipulation functions, functional programming constructs, etc.

Compile generates a CompiledFunction object.

Compiled code does not handle numerical precision and local variables in the same way as ordinary Mathematica code.

If a compiled function cannot be evaluated with particular arguments using compiled code, ordinary Mathematica code is used instead.

Ordinary Mathematica code can be called from within compiled code. Results obtained from the Mathematica code are assumed to be approximate real numbers, unless specified otherwise by the third argument of Compile.

The number of times and the order in which objects are evaluated by Compile may be different from ordinary Mathematica code.

Compile has attribute HoldAll, and does not by default do any evaluation before compilation.

You can use Compile[ ... , Evaluate[expr]] to specify that expr should be evaluated symbolically before compilation.

See The Mathematica Book: Section 1.11.8 and Section 2.5.14.

See also: Dispatch, Function, InterpolatingFunction, CForm.

Further Examples