Overview of the CodeGeneration Package - Maple Programming Help

Home : Support : Online Help : Programming : Packages : CodeGeneration

Overview of the CodeGeneration Package

Basic Functionality

Description

 • The CodeGeneration package is a collection of commands and subpackages that enable the translation of Maple code to other programming languages.

Output

 • Translated source code in the target language.

Code Generation Assistant

 • You can generate code using an interactive template with the Code Generation Assistant.

Accessing CodeGeneration Package Commands

 • Each command in the CodeGeneration package can be accessed by using the long form or the short form of the command in the command calling sequence.
 Long form
 > CodeGeneration[C]([[x, 2*y], [5, z]]);
 Short form
 > with(CodeGeneration);
 > C([[x, 2*y], [5, z]]);

Essential CodeGeneration Package Commands

 translate Maple code to C code translate Maple code to C# code translate Maple code to Fortran code translate Maple code to Java code translate Maple code to JavaScript code translate Maple code to Julia code translate Maple code to MATLAB(R) code translate Maple code to Perl code translate Maple code to Python code translate Maple code to R code translate Maple code to VisualBasic code

Examples

 > $\mathrm{with}\left(\mathrm{CodeGeneration}\right)$
 $\left[{C}{,}{\mathrm{CSharp}}{,}{\mathrm{Fortran}}{,}{\mathrm{IntermediateCode}}{,}{\mathrm{Java}}{,}{\mathrm{JavaScript}}{,}{\mathrm{Julia}}{,}{\mathrm{LanguageDefinition}}{,}{\mathrm{Matlab}}{,}{\mathrm{Names}}{,}{\mathrm{Perl}}{,}{\mathrm{Python}}{,}{R}{,}{\mathrm{Save}}{,}{\mathrm{Translate}}{,}{\mathrm{VisualBasic}}\right]$ (1)

Generate C code

 > $C\left(x+y+z-2xz\right)$
 cg = -2 * x * z + x + y + z;

Generate MATLAB® code

 > $\mathrm{Matlab}\left(\left[\left[x,2y+z\right],\left[xy,z\right]\right]\right)$
 cg0 = [x 2 * y + z; x * y z;];

Generate Visual Basic code

 > $\mathrm{VisualBasic}\left(\left[s=1.0+x,t=\mathrm{ln}\left(s\right){ⅇ}^{-x},r={ⅇ}^{-x}+xt\right]\right)$
 s = 0.10E1 + x t = Log(s) * Exp(-x) r = Exp(-x) + x * t

Details

 • options available to alter the translated output
 • extending the CodeGeneration package using the LanguageDefinition subpackage
 see the Details of the CodeGeneration Package help page.