Code Generation - Maple Programming Help

 Code Generation

The CodeGeneration package offers new support for translating Maple code to the Julia programming language.

Julia

With CodeGeneration[Julia], you can translate expressions to code fragments:

 > $\mathrm{with}\left(\mathrm{CodeGeneration}\right):$
 > $\mathrm{Julia}\left(\sqrt{{a}^{2}+{b}^{2}+{c}^{2}}\right)$
 cg = sqrt(a ^ 2 + b ^ 2 + c ^ 2)

You can also translate procedures and larger programs.

 > $\mathrm{Julia}\left(m\to \mathrm{add}\left(i,i=1..m\right)\right)$
 function cg0(m)     r = 0     for i = 1:m         r = r + i     return(r) end

CodeGeneration[Julia] translates many Maple data structures and functions, including many routines for linear algebra and special functions, to equivalents in Julia.

 > $\mathrm{Julia}\left(\left[\begin{array}{rr}1& 2\\ 3& 4\end{array}\right]\right)$
 cg1 = [1 2; 3 4]
 > $\mathrm{Julia}({\begin{array}{cc}-{v}^{3}+3v+1& v<1\\ 2{v}^{3}-9{v}^{2}+12v-2& v<2\\ -{v}^{3}+9{v}^{2}-24v+22& \mathrm{otherwise}\end{array})$
 cg2 = -v ^ 3 + 3 * v + 1 ? v < 1 : 2 * v ^ 3 - 9 * v ^ 2 + 12 * v - 2 ? v < 2 : -v ^ 3 + 9 * v ^ 2 - 24 * v + 22
 >
 cg3(M,n) = M - x * eye(n)
 > $\mathrm{Julia}\left(\mathrm{_C1}\mathrm{BesselJ}\left(\mathrm{\nu },x\right)+\mathrm{_C2}\mathrm{BesselY}\left(\mathrm{\nu },x\right)\right)$
 cg4 = _C1 * besselj(nu, x) + _C2 * bessely(nu, x)

Code Generation for Julia in Maple can also translate some key commands from Statistics:

 > $\mathrm{Julia}\left('\mathrm{Statistics}:-\mathrm{Mean}\left(\left[5,2,1,4,3\right]\right)'\right)$
 cg5 = mean([5,2,1,4,3])
 > $\mathrm{Julia}\left('\mathrm{Statistics}:-\mathrm{Median}\left(\left[5,2,1,4,3\right]\right)'\right)$
 cg6 = median([5,2,1,4,3])
 > $\mathrm{Julia}\left('\mathrm{Statistics}:-\mathrm{StandardDeviation}\left(\left[5,2,1,4,3\right]\right)'\right)$
 cg7 = std([5,2,1,4,3])

When possible, Maple attempts to return an equivalent command to commands dealing with many distributions. In this example, the evaluated probability density function is translated.

 > $\mathrm{Julia}\left(\mathrm{Statistics}:-\mathrm{PDF}\left(\mathrm{LogNormal}\left(0,1\right),x\right)\right)$
 cg9 = 0 ? x < 0 : 1 / x * sqrt(2) * pi ^ (-1//2) * exp(-log(x) ^ 2 / 2) / 2