## WeBWorK Main Forum

### Check function-type answers by properties, not by formulas ### Check function-type answers by properties, not by formulas

by Philip Loewen -
Number of replies: 2

Some problems have more than one correct answer, each of type "function". E.g., "Find a function f, with f(0) nonzero, satisfying the identity f"(x)+f(x)=0 for all x." What is the approved method for checking student submissions in such questions?

For the example here, my first idea is to build a custom answer-checker that assigns the student's response to an object $f, and then defines my$z = $f->D('x','x') +$f;

Now I just need to determine if $z coincides with the zero function. I know that the answer-checker built in to WW does this kind of thing all the time. Is there a standard way for me to access this functionality in the current situation? (Right now I evaluate$z for a bunch of x-values and add up the moduli of the values I get, hoping for a very small sum. This feels like reinventing the wheel.)

This example is a simple representative for a whole class of problems, so I'm hoping to arrive at a rather general solution eventually. Nonetheless, a suggestion customized to this particular instance would already expand my understanding and be much appreciated. ### Re: Check function-type answers by properties, not by formulas

by Davide Cervone -
You can use

if ($z == Formula("0")) { ... }  or even  if ($z == 0) {
...
}

to check if your function is the zero function. MathObjects overloads the equality operator to perform the usual WeBWorK formula equality check (using several random points and the current context tolerances and tolerance type). 