WeBWorK Problems

Division is allowed only for Numbers or a Vector, Point, or Matrix and a Number

by Peter Selinger -
Number of replies: 3

Library/WHFreeman/Holt_linear_algebra/Chaps_1-4/3.3.54.pg

The problem works beautifully when the student enters the correct answer, for example

(A-CB)^(-1) * CD.

However, when the student enters an incorrect answer, for example

(A-CB)^(-1) * CA,

they not only get the result "incorrect", but also the incomprehensible warning message

"Division is allowed only for Numbers or a Vector, Point, or Matrix and a Number".

The message is inappropriate because there is actually no division. The formula only contains the inverse of a matrix (and this is well-defined, and in fact necessary for the correct answer).

The message also appears on "Preview My Answers", but only if an incorrect answer is entered.

How can I turn off this spurious warning message?

Thanks, -- Peter

Re: Division is allowed only for Numbers or a Vector, Point, or Matrix and a Number

by Peter Selinger -
P.S.: further to my question about the library question

Library/WHFreeman/Holt_linear_algebra/Chaps_1-4/3.3.54.pg

and the strange error message that it generates, "Division is allowed only for Numbers or a Vector, Point, or Matrix and a Number": I did find the place where the error message is generated, namely in the function _check() in lib/Parser/BOP/divide.pm. Looking at the code (but not understanding how it is used), I tried adding

to the problem. However, instead of solving the issue, this generates the even less comprehensible error messages

and

Use of uninitialized value \$new_rh_ans_evaluation_result in concatenation (.) or string at /opt/webwork/pg/lib/WeBWorK/PG/Translator.pm line 1337

Does anyone understand what is going on here? The "allowBadOperands" option is documented here: webwork.maa.org/wiki/Context_flags, but it seems to cause unrelated problems.

Help! I am using this problem in a live problem set with students right now, and I had to add a message to the students to please ignore the error message. I don't know what causes it or how to turn it off.

Re: Division is allowed only for Numbers or a Vector, Point, or Matrix and a Number

by Davide Cervone -
You don't want to use allowBadOperands. That is for the Typeset context so that incomplete expressions can be parsed and typeset. That will cause all kinds of trouble for problems that need to be able to evaluate the resulting formulas.

The issue is that there is a reduction rule for a power of minus one that turns x^(-1) into 1/x. This was written before support for matrix inverses was added, so it wasn't a problem then, but it is trying to turn M^(-1) into 1/M even when M is a matrix.

You can get around this by adding

Context()->noreduce('x^(-1)');

after the other modifications to the context.

I will have to submit a patch in order to fix the issue.