11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

30 • Chapter 2: Procedures, Variables, and Extending MapleWriting the structure once reduces the risk of errors. When you havedefined the variable ‘type/name‘, you can use name as a type.> ‘type/Variables‘ := {name, list(name), set(name)}:> type( x, Variables );true> type( { x[1], x[2] }, Variables );trueIf the structured type mechanism is not powerful enough, you candefine a new type by assigning a procedure to a variable of the form‘type/name‘. When you test whether an expression is of type name,Maple invokes the procedure ‘type/name‘ on the expression if such aprocedure exists. Your procedure should return true or false. The following‘type/permutation‘ procedure determines if p is a permutationof the first n positive integers. That is, p should contain exactly one copyof each integer from 1 through n.> ‘type/permutation‘ := proc(p)> local i;> type(p,list) and { op(p) } = { seq(i, i=1..nops(p)) };> end proc:> type( [1,5,2,3], permutation );false> type( [1,4,2,3], permutation );trueYour type-testing procedure can accept more than one parameter.When you test if an expression, expr, has type name(parameters), thenMaple invokes‘type/name‘( expr, parameters )if such a procedure exists. The following ‘type/LINEAR‘ procedure determinesif f is a polynomial in V of degree 1.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!