## WeBWorK Problems

### Bug(s) (or user error?) with D derivative method ### Bug(s) (or user error?) with D derivative method

by Alex Jordan -
Number of replies: 2
I discovered the following, trying to write a check to establish if a student's answer for a series question is a p-series. [As a side note, if anyone has a suggestion for a better way to accomplish this, I'd love to hear it.] Here is a minimal code snippet example of the issue.

$myf= Formula("1/n");$mydf=$myf->D('n');$shouldbeminusone = ($myf/$mydf)/Formula("n");
$shouldbezero=$shouldbeminusone ->D('n');
#
BEGIN_PGML
[@$mydf@] [@$shouldbeminusone@]

[@$shouldbezero@] END_PGML This outputs three lines: (-1)/(n^2) 1/n/[1/(n^2)]/n ([1/(n^2)*1/(n^2)-1/n*2*n/[(n^2)^2]]/[(-[1/(n^2)])^2]*n-1/n/[1/(n^2)])/(n^2) The top line is the correct derivative of 1/n. The second line should be displaying 1/n/[(-1)/(n^2)]/n but the minus sign is missing. This is issue #1. Regardless of whether the second line reduces to 1 or -1, the bottom line is defined as its derivative, and should simplify to 0. But it simplifies to -2/n. (Try copying and pasting it into WolframAlpha to see this. In any case, in PG it is being counted as equal to Formula("0").) This is issue #2. And so my check that this equals Formula("0") (as a way to check whether the original thing was a p-series) fails. Something about D is not working here. Or I am not using D correctly. In reply to Alex Jordan ### Re: Bug(s) (or user error?) with D derivative method by Alex Jordan - Here is evidence that the D method is altering what you apply it to. For instance, if you comment out the line in the minimal example that calls D on$shouldbeminusone then when \$shouldbeminusone is displayed, the minus sign no longer is dropped. 