WeBWorK Problems

Problems with the PolynomialFactors context

Problems with the PolynomialFactors context

by Glenn Rice -
Number of replies: 2
Something seems to be wrong with the PolynomialFactors context from contextPolynomialFactors.pl.

If you use singleFactors => 1, and the student enters -(x+6)(x+2) (for example) then the error message "Only one factor or constant can be negated" is given. Of course, that is silly when only one factor is.

Throwing some warn's into the macro for debugging purposes shows that the checkPolynomial method of the PolynomialFactors::UOP::minus package is called twice. One with $op == (x+6) and again with $op == (x+6)(x+2). Of course the second call is the problem.
In reply to Glenn Rice

Re: Problems with the PolynomialFactors context

by Davide Cervone -
The source of the error is that Forumla objects to a post-processing phase where they student answer is reduced (in order to force some incorrect uses of functions to be flagged). It is this reduction that is causing the unwanted message, because the standard reductions include trying to move negative outside multiplication, and the formula -(x+6)(x_2) is parsed as (-(x+6))*(x+2). The reduction rules try to make it -((x+6)(x+2)), which is where the error is produced.

One solution would be to disable the reduction rules in the PolynomialFactors context. Another would be to disable the post-processing in this context. Since none of the other actions taken by the post-processing are important for polynomials, I've taken the latter approach, and disabled the post-processing.

You can find the needed changes in the pull request that I've made to perform the fix.
In reply to Davide Cervone

Re: Problems with the PolynomialFactors context

by Glenn Rice -
I see. Thanks for your response. That gives me enough to work with for now.