## PREP 2013 Question Authoring - Archived

### Is there a way to "force" the order of terms in a polynomial?

by Mary Shepherd -
Number of replies: 4
Is there a way to "force" the order of terms in a polynomial? I'm working on some of the developmental problems and I would like problems where an answer of, say, 4 + w is correct, but w + 4 is not, or w*4 is correct but 4*w is not. I haven't seen anything in the documentation that would lead me to think I could do this in one answer box.

Mary

### Re: Is there a way to "force" the order of terms in a polynomial?

by Davide Cervone -
There is no current mechanism for doing what you ask.

It would be possible to modify the contextLimitedPolynomial.pl file to include such functionality, but it is non-trivial and beyond the scope of this course. I'll put it in my queue of feature requests.

An alternative would be to use a custom answer checker or an answer post-filter to check the format. How you do that depends on what type of error messages you want. For example, if you only care about giving positional hints for the correct answer, then you could use a custom answer checker that first checks if the answers are equal, and if they are, then converts the student answer to a string and compares that to the correct answer string, and gives a message about not having things in the right order otherwise.

Something like the following should work:

    loadMacros("contextLimitedPolynomial.pl");

Context("LimitedPolynomial-Strict");

$f = Compute("x^2+3x-1"); Context()->texStrings; BEGIN_TEXT $$f$$ = \{$f->ans_rule\}
END_TEXT
Context()->normalStrings;

ANS($f->cmp(checker => sub { my ($correct,$student,$ans) = @_;
return 0 unless $correct ==$student;
Value->Error("Check the order of your terms or coefficients")
unless $correct->string eq$student->string;
return 1;
}));

The error message can't be made very specific in this case, because you don't know exactly what the problem is, so a modified LimitedPolynomial context would be better, but that would be considerably harder.

Hope that is sufficient.

Davide

### Re: Is there a way to "force" the order of terms in a polynomial?

by Mary Shepherd -
Davide,

I tried your suggestion and could get it to work for addition, but not for multiplication where I need something like x*7 to be a student answer. In this case I keep getting an error message that the coefficient must come before the variable. I will continue trying things and see if I come up with a solution. Thanks for your guidance above.--Mary

### Re: Is there a way to "force" the order of terms in a polynomial?

by Mary Shepherd -
Davide,

I got the "order" to matter for multiplication. I used the answer checker to check the string the student input, but had to leave the Context("Numeric"), apparently so that the coefficient did not have to be before the variable.--Mary
Sorry, I didn't pick up your original statement about wanting x*7 rather than 7*x. The polynomial context uses coefficients before the variable, as is customary for polynomials. So my approach won't work for you, as you have found. Sorry!