## WeBWorK Problems

### answers that are Sets and a custom checker issue

by Alex Jordan -
Number of replies: 1
I have a class of problems I would like to write about simplifying rational expressions. For example:

Simplify the following expression:
(x / (x-1)) / x

The straightforward answer is 1/(x-1), which can easily be coded as a MathObject using contextRationalFunciton.pl.

I want to go the extra mile and make students recognize that the simplification is not valid for x=0. I want to follow up the first question with a second one asking for all x-values where the simplification is not valid. The answer I have in mind is the Set {0} using the built-in Interval context for Sets. (I think that I would prefer that the answer be a Set, but if a solution to my issue can be found with a List, I will settle for that.)

Some students will naturally be inclined to answer with {0,1}, since 1 is not in the domain. I do *not* want this to count as incorrect.

So here is my issue: I have a MathObject Set R that is the ideal correct response. It is contained in a larger set T. I want to count any set S with R<=S<=T as correct.

I have tried using a custom answer checker in the following way:

Context("Interval");
$ans = Set("{0}");$extras = Set("{1}");
$together = Set("$ans U $extras"); ANS($ans->cmp( checker=>sub{
my ($correct,$student, $ansHash ) = @_; if ((Set("$correct")->isSubsetOf("$student")) && (Set("$student")->isSubsetOf(Set("$together")))) {return 1;} else {return 0;}; })); Some of those Set commands may seem extraneous, but I get errors without them. Anyway, the real problem is that this behaves just as if I were not using a custom answer checker at all. It treats {0} as correct, and gives 50% credit for {0,1} with an error message that the second value is not correct. Does anyone understand the inner workings of MathObjects enough to understand why this is happening? Thank you, Alex In reply to Alex Jordan ### Re: answers that are Sets and a custom checker issue by Davide Cervone - The reason for your troubles is that a Set is actually a special kind of List, and so the answer checker in use is actually the list answer checker. The list answer checker calls your checker on each entry in the list, not on the list as a whole. That is probably why you needed the extra Set() commands (and that might have been a red flag that something was not quite as expected). Rather than using checker, you should use list_checker so that you replace the complete list checker rather than the individual entry checker. In that case, $correct and $student are array references rather than MathObjects, and they point to arrays containing the elements of the lists (in this case, the elements in the set). So you do have to put them back into sets. Here is an example:  ANS($ans->cmp( list_checker=>sub{
my ($correct,$student, $ansHash ) = @_;$correct = Set(@{$correct});$student = Set(@{$student}); return ($correct->isSubsetOf($student) &&$student->isSubsetOf($together) ?$student->length : 0);
}

Note that the list_checker returns the number of correct entries in the student answer, so that is why we use \$student->length as the return value when the answer is correct.

I know it is too late for your question, but I hope this helps someone in the future.

Davide