WeBWorK Main Forum

What kind of answer checker is needed for lists of algebraic expressions?

What kind of answer checker is needed for lists of algebraic expressions?

by James Mc Laughlin -
Number of replies: 5

I would like to have the answer checker recognize

an expression such as 

             e,a^6,a^12,a^18,a^24

as a correct answer.


Separate from this and in other problems, I would like Webwork to recognize

{e,a^6,a^12,a^18,a^24}

as a correct answer.


What I tried was 

ANS(fun_cmp("e,a^6,a^12,a^18,a^24", vars=>['e','a']));

for one, and 

ANS(fun_cmp("{e,a^6,a^12,a^18,a^24}", vars=>['e','a']));

for the other.

Both give errors when I try to enter these as answers. 

The former gives an error message 

"Your fifth formula is incorrect"

while the second gives the error message 

"The parentheses for your list seem to be missing"

I cannot find anything online, and nothing else that I have tried works either.


It is driving me nuts, so any help greatly appreciated.


Thanks.


In reply to James Mc Laughlin

Re: What kind of answer checker is needed for lists of algebraic expressions?

by Nathan Wallach -

I'm tossing some ideas your way.

Have a look at https://webwork.maa.org/wiki/List_(MathObject_Class) which can handle ordered and unordered lists. Add the relevant variables to your context. 

I think you may want to avoid "e" as it is usually included in the standard contexts as a constant. but it should probably be possible to remove the constant and then use "e" as a variable. However, it might confuse students. See: https://webwork.maa.org/wiki/Introduction_to_Contexts for an explanation on adding/removing constants and variables.

Large exponents lead to large values during testing, which can make setting a suitable tolerance somewhat challenging. You probably need to select "good" limits from where the test points can be selected to handles answers with things like a^24.

In reply to Nathan Wallach

Re: What kind of answer checker is needed for lists of algebraic expressions?

by James Mc Laughlin -
I tried using
$L1 = List(e,a^6,a^12,a^18,a^24);

ANS($L1->cmp);

in an earlier attempt, but that generates a couple of errors.

If put $L1 in the text of the problem just to see what it looks like, it prints "\text{e}, 6, 12, 18, 24".

If I put e,a^6,a^12,a^18,a^24 in the answer box, it objects to the ^ and returns the error
"Operands of '^' can't be words"

I will keep tinkering to see if I can get it worked out.
In reply to James Mc Laughlin

Re: What kind of answer checker is needed for lists of algebraic expressions?

by Alex Jordan -

> $L1 = List(e,a^6,a^12,a^18,a^24);

That wouldn't work, but:

$L1 = List("e,a^6,a^12,a^18,a^24");

would work if "e" and "a" are defined in the Context as variables.

Also, these should work:

$L1 = Formula("e,a^6,a^12,a^18,a^24");   # the parser will figure out from the commas to make a List

$L1 = Compute("e,a^6,a^12,a^18,a^24");  # the parse will figure out to make it a Formula, then a List

To make "a" recognized as a variable in the context, before the $L1 declaration, use:

Context()->variables->add(a=>"Real");

"e" will already be recognized as a constant in the context, so you can remove it, then make it a variable:

Context()->constants->remove("e");
Context()->variables->add(e=>"Real");

Or together:

Context()->constants->remove("e");
Context()->variables->add(a=>"Real", e=>"Real");

Is this for a problem about groups? If so, using variables "e" and "a" in the Numeric context is a little off. For example "2e-e" will be accepted when "e" is the answer, even though that expression doesn't mean anything in the context of a group. Maybe that is of no concern. But also if when a student enters a wildly incorrect answer, they might see feedback messages like "you're answer should be a list of formulas that return numbers" which could lead to head scratching.  I think someone (maybe Paul Pearson?) was working on a context for group theory, but I didn't find it after a short search.

In reply to Alex Jordan

Re: What kind of answer checker is needed for lists of algebraic expressions?

by James Mc Laughlin -

I just tried what you suggested and it did work - thanks for the suggestions.

It is for a problem about groups - I will maybe try to refine the problem at some later date to avoid the issues you mentioned.

In reply to Nathan Wallach

Re: What kind of answer checker is needed for lists of algebraic expressions?

by James Mc Laughlin -

I figured a workaround, using Formula( ), but had to use x instead of a.


$f1 = Formula("e,x^6,x^12,x^18,x^24"); 

ANS($f1->cmp);


For the {e,x^6,x^12,x^18,x^24}, I just left the { } in the text of the problem and used the above method.