Exemplo n.º 1
0
 public void compileDerivative(
     ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt) {
   // The ExpressionCommand occurs in the program prog at the index indicated by myIndex.
   // Add commands to deriv that will evaluate the derivative of this command with respect to
   // the variable wrt.  Note that the "Cmd" object is preceded in the program by commands that
   // compute the lower and upper limits of the summation.
   if (!sumExpr.dependsOn(wrt)) deriv.addConstant(0);
   else {
     int upper = prog.extent(myIndex - 1); // Size of expression giving the upper limit.
     prog.copyExpression(myIndex - 1 - upper, deriv); // Copy lower limit exression to deriv.
     prog.copyExpression(myIndex - 1, deriv); // Copy upper limit expression to deriv.
     deriv.addCommandObject(new Cmd(sumVar, (ExpressionProgram) sumExpr.derivative(wrt)));
   }
 }