CodeGeneration - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Code Generation Package : Julia : CodeGeneration/Julia

CodeGeneration

  

Julia

  

translate Maple code to Julia code

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

Julia(x, cgopts)

Parameters

x

-

expression, list, rtable, procedure, or module

cgopts

-

(optional) one or more CodeGeneration options

Description

• 

The Julia(x, cgopts) calling sequence translates Maple code to Julia code.

  

- If the parameter x is an algebraic expression, then a Julia statement assigning the expression to a variable is generated.

  

- If x is a list, Maple Array, or rtable of algebraic expressions, then a sequence of Julia statements assigning the elements to a Julia array is produced.  Only the initialized elements of the rtable or Maple Array are translated.

  

- If x is a list of equations nm=expr, where nm is a name and expr is an algebraic expression, then this is understood as a sequence of assignment statements.  In this case, the equivalent sequence of Julia assignment statements is generated.

  

- If x is a procedure, then a Julia function is generated which is equivalent to the procedure, along with any necessary import statements.

• 

The parameter cgopts may include one or more CodeGeneration options, as described in CodeGenerationOptions.

• 

For more information about how the CodeGeneration package translates Maple code to other languages, see Translation Details. For more information about translation to Julia in particular, see Julia Details.

Examples

For a description of the options used in the following examples, see CodeGenerationOptions.

withCodeGeneration:

Translate a simple expression and assign it to the name w in the target code.

Juliax+yz2xz,resultname=w

w = -2 * x * z + y * z + x

Translate a list and assign it to an array with the name w in the target code.

Juliax,2y,5,z,resultname=w

w = [[x,2 * y],[5,z]]

Translate a computation sequence.  Optimize the input first.

css=1.0+x,t=lnsexpx,r=expx+xt:

Juliacs,optimize

s = 0.10e1 + x
t1 = log(s)
t2 = exp(-x)
t = t2 * t1
r = x * t + t2

Declare that x is a float and y is an integer. Return the result in a string.

sJuliax+y+1,declare=x::float,y::'integer',output=string

scg = x + y + 1

(1)

Translate a procedure.  Assume that all untyped variables have type integer.

f := proc(x, y, z) return x*y-y*z+x*z; end proc:

Juliaf,defaulttype=integer

function f(x, y, z)
    return(y * x - y * z + x * z)
end

Translate a procedure containing an implicit return.  A new variable is created to hold the return value.

f := proc(n)
  local x, i;
  x := 0.0;
  for i to n do
    x := x + i;
  end do;
end proc:

Juliaf

function f(n)
    x = 0.0e0
    for i = 1:n
        x = x + i
        cgret = x
    end
    return(cgret)
end

Translate a linear combination of hyperbolic trigonometric functions.

Julia2coshx7tanhx

cg0 = 2 * cosh(x) - 7 * tanh(x)

Translate a procedure with no return value containing a printf statement.

f := proc(a::integer, p::integer)
  printf("The integer remainder of %d divided by %d is: %d\n", a, p, irem(a, p));
end proc:

Juliaf

function f(a, p)
    printf("The integer remainder of %d divided by %d is: %d\n", a, p, a % p)
end

Translate a procedure involving linear algebra.

detHilbert := proc(M, n :: posint) uses LinearAlgebra;
   return Determinant( HilbertMatrix( n ) );
end proc:

JuliadetHilbert

function detHilbert(M, n)
    return(det(LinearAlgebra:-HilbertMatrix(n)))
end

Compatibility

• 

The CodeGeneration[Julia] command was introduced in Maple 2016.

• 

For more information on Maple 2016 changes, see Updates in Maple 2016.

See Also

CodeGeneration

CodeGenerationOptions

JuliaDetails

TranslationDetails