cost - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


codegen

  

cost

  

operation evaluation count

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

cost(x1, x2,...,xn)

Parameters

xk

-

of type algebraic, name = algebraic, array(algebraic)

Description

• 

The cost command is used to compute an operation count for the numerical evaluation of the given arguments. The operation count is expressed as a polynomial in the names additions, multiplications, assignments, divisions, functions, storage, subscripts, integrals, products and assignments with non-negative integer coefficients.

• 

Assignment of positive real values to these global names yields a weighted cost.

• 

Note that the cost used for computing powers is as follows. For an integral power, repeated multiplication is assumed. For a general power it is assumed to be computed using exp and ln.

• 

The command with(codegen,cost) allows the use of the abbreviated form of this command.

Examples

withcodegen,cost,optimize:

ax+x2+x3+x4:

costa

3additions+6multiplications

(1)

aconverta,horner:

costa

3multiplications+3additions

(2)

Using numeric values to express the relative costs of various operations, you can derive a numerical measure of the cost of an expression or procedure. This can then be used to evaluate whether or not to use an optimized version.

rprandpolyx,y,z:

punapplyrp,x,y,z:

po1optimizep:po2optimizep,:-tryhard:

ccostp:

c1costpo1:

c2costpo2:

cc1;cc2;c1c2

4multiplications5storage5assignments

8multiplications2storage2assignments

3storage+3assignments+4multiplications

(3)

Vstorage=2,additions=1,assignments=1,functions=100,multiplications=20:

evalc,V

424

(4)

evalc1,V

359

(5)

evalc2,V

270

(6)

See Also

codegen[optimize]