Search
Compiling_and_Generating_Code
Untitled (the Wolfram Language for Students - Personal Use Only : www.wolfram.com)

Code compilation

Mathematica code is by default interpreted by the Mathematica kernel

The kernel can also compile a subset of Mathematica code for better performance

e.g. approximate π numerically

Compiling_and_Generating_Code_1.png

Compiling_and_Generating_Code_2.png

Truncate this sum at n terms

Compiling_and_Generating_Code_3.png

Compiling_and_Generating_Code_4.png

Compiling_and_Generating_Code_5.png

Compiling_and_Generating_Code_6.png

Compiling_and_Generating_Code_7.png

Compiling_and_Generating_Code_8.png

Compiling_and_Generating_Code_9.gif

Compiling_and_Generating_Code_10.png

Compiling_and_Generating_Code_11.png

Compiling_and_Generating_Code_12.png

Compiling_and_Generating_Code_13.png

Compiling_and_Generating_Code_14.png

Generating code

Compiling_and_Generating_Code_15.png

Compiling_and_Generating_Code_16.png

Compiling_and_Generating_Code_17.png

Compiling_and_Generating_Code_18.png

Compiling_and_Generating_Code_19.png

JIT Compilation

Suppose we want to roll our own JIT compilation

We want to speed up Select, which returns those elements of a list that match a pattern

Compiling_and_Generating_Code_20.png

Compiling_and_Generating_Code_21.png

Compiling_and_Generating_Code_22.png

Compiling_and_Generating_Code_23.png

Compiling_and_Generating_Code_24.png

Compiling_and_Generating_Code_25.png

Compiling_and_Generating_Code_26.png

Compiling_and_Generating_Code_27.png

Compiling_and_Generating_Code_28.png

Compiling_and_Generating_Code_29.png

Compiling_and_Generating_Code_30.png

Compiling_and_Generating_Code_31.png