11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

This is achieved by the double assignment of> a, b := op( 1, expr ), subsop( 1 = 1, expr );3.1 Syntax and Semantics • 61so the input expression expr is expressed as expr = a * b. The standardtechnique of returning unevaluated is used so that computation canproceed symbolically on expressions that the procedure is unable to differentiate.This first example is simple, but it is already able to handle polynomialswith numeric coefficients.> differentiate( 2 - x + x^2 + 3*x^9, x );−1 + 2 x + 27 x 8However, it fails on expressions containing calls to standard mathematicalfunctions.> differentiate( sin( x ), x );differentiate(sin(x), x)It is also unable to deal successfully with symbolic coefficients.> differentiate( a*x^2 + b*x + c, x );differentiate(a, x) x 2 + 2 a x + differentiate(b, x) x + b+ differentiate(c, x)Adding Missing Functionality To add the missing functionality, add acase for expressions of type function.> differentiate := proc( expr, var )> local a, b;>> if not has( expr, var ) then> 0> elif expr = var then> 1> elif type( expr, ’‘+‘’ ) then> map( procname, args )> elif type( expr, ’‘^‘’ ) then> a, b := op( expr );> if not has( b, var ) then> b * a ^ ( b - 1 ) * procname( a, var )> else> ’procname( args )’

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

Saved successfully!

Ooh no, something went wrong!