Mathematica code generation nearly done