Code Generation - Maple Help

Online Help

All Products    Maple    MapleSim


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:

withCodeGeneration:

Juliaa2+b2+c2

cg = sqrt(a ^ 2 + b ^ 2 + c ^ 2)

 

You can also translate procedures and larger programs.

Juliamaddi,i=1..m

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.

Julia1234

cg1 = [1 2; 3 4]

Julia&lpar;&lcub;v3&plus;3v&plus;1v<12v39v2&plus;12v2v<2v3&plus;9v224v&plus;22otherwise&rpar;

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

JuliaM&comma;nM  x LinearAlgebra:-IdentityMatrixn

cg3(M,n) = M - x * eye(n)

Julia_C1BesselJν&comma;x&plus;_C2BesselYν&comma;x

cg4 = _C1 * besselj(nu, x) + _C2 * bessely(nu, x)

 

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

Julia&apos;Statistics:-Mean5&comma;2&comma;1&comma;4&comma;3&apos;

cg5 = mean([5,2,1,4,3])

Julia&apos;Statistics:-Median5&comma;2&comma;1&comma;4&comma;3&apos;

cg6 = median([5,2,1,4,3])

Julia&apos;Statistics:-StandardDeviation5&comma;2&comma;1&comma;4&comma;3&apos;

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.

JuliaStatistics:-PDFLogNormal0&comma;1&comma;x

cg9 = 0 ? x < 0 : 1 / x * sqrt(2) * pi ^ (-1//2) * exp(-log(x) ^ 2 / 2) / 2