creates a compiled function that evaluates expr assuming numerical values of the xi.


assumes that xi is of a type that matches ti.


assumes that xi is a rank ni array of objects, each of a type that matches ti.


assumes that subexpressions in expr that match pi are of types that match pti.

Details and Options

  • The types handled by Compile are:
  • _Integermachinesize integer
    _Realmachineprecision approximate real number (default)
    _Complexmachineprecision approximate complex number
    True | Falselogical variable
  • 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, and 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 Wolfram Language code.
  • If a compiled function cannot be evaluated with particular arguments using compiled code, ordinary Wolfram Language code is used instead.
  • Ordinary Wolfram Language code can be called from within compiled code. Results obtained from the Wolfram Language 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 Wolfram Language 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.
  • The following options can be given:
  • CompilationOptionsAutomaticoptions for the compilation process
    CompilationTarget$CompilationTargetthe target runtime for code generation
    ParallelizationAutomaticparallel controls for compiled function execution
    RuntimeAttributes{}evaluation attributes for the compiled function
    RuntimeOptionsAutomaticruntime options for the compiled function


open all close all

Basic Examples  (1)

Compile the function Sin[x]+x^2-1/(1-x) for machine real x:

Click for copyable input

The CompiledFunction evaluates with machine numbers:

Click for copyable input

Plot the compiled function:

Click for copyable input

Scope  (1)

Options  (9)

Possible Issues  (1)

Neat Examples  (1)

Introduced in 1991
Updated in 2010