PREP 2014 Question Authoring - Archived

Only last of several UNORDERED_ANS pairs works

Only last of several UNORDERED_ANS pairs works

by Mary Cameron -
Number of replies: 5
I would like to have several pairs of answers to be correct, regardless of their order.  However, it appears that only the last in a sequence of UNORDERED_ANS calls seems to work.  Any ideas on how to make this work?  The code follows.

Thanks,  
Mary Cameron

DOCUMENT();        
loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
"MathObjects.pl",                
"unorderedAnswer.pl",       #   DOESN"T APPEAR TO WORK in all instances
);

TEXT(beginproblem());

Context()->variables->add(y=>"Real");        
$h = 1;   
$k = 2;     
$ansa = Compute("x-$h")->reduce();       
$ansb = Compute("y-$k")->reduce();       

$three = Compute("3");
$four = Compute ("4");

Context()->texStrings;      
BEGIN_TEXT
$BR Enter 3 and 4 in any order  \{ ans_rule(4) \}    \{ ans_rule(4) \}     
$BR Enter $ansa and $ansb in any order  \{ ans_rule(4) \}    \{ ans_rule(4) \}     
END_TEXT

### conclusion -- only the last unorderedAnswer pair seems to work:
Context()->normalStrings;      
UNORDERED_ANS($three->cmp(), $four -> cmp() );
UNORDERED_ANS( $ansa->cmp(), $ansb->cmp() );      

ENDDOCUMENT();   
In reply to Mary Cameron

Re: Only last of several UNORDERED_ANS pairs works

by Davide Cervone -
The unordered answer macros are pretty ancient, and not all the facilities that we have today were available when they were written. It turns out that UNANSWERED_ANS() is a bit finicky, and you have to call it directly after the answer rules that it applies to (with no additional ones in between), or it will get messed up.

So you should do something like:

DOCUMENT();
loadMacros(
  "PG.pl",
  "PGbasicmacros.pl",
  "PGchoicemacros.pl",
  "PGanswermacros.pl",
  "PGauxiliaryFunctions.pl",
  "MathObjects.pl",                
  "unorderedAnswer.pl",
);

TEXT(beginproblem());

Context()->variables->add(y=>"Real");        
$h = 1;   
$k = 2;     
$ansa = Compute("x-$h")->reduce();       
$ansb = Compute("y-$k")->reduce();       

$three = Compute("3");
$four = Compute ("4");

Context()->texStrings;      
BEGIN_TEXT
$BR Enter 3 and 4 in any order  \{ ans_rule(4) \}    \{ ans_rule(4) \}     
END_TEXT

UNORDERED_ANS($three->cmp(), $four -> cmp() );

BEGIN_TEXT
$BR Enter $ansa and $ansb in any order  \{ ans_rule(4) \}    \{ ans_rule(4) \}     
END_TEXT
Context()->normalStrings;      

UNORDERED_ANS( $ansa->cmp(), $ansb->cmp() );

ENDDOCUMENT();
See if that helps.

Davide

In reply to Davide Cervone

Re: Only last of several UNORDERED_ANS pairs works

by Mary Cameron -
Yes -- splitting up BEGIN_TEXT blocks works.  Thank you !
In reply to Davide Cervone

Re: Only last of several UNORDERED_ANS pairs works

by Chrissy Safranski -
I didn't know UnorderedAnswer existed until this thread.  Is this a good thing to use instead of MultiAnswer if the only thing we're trying to allow is 2 answers, entered in either order?  Does it work for more answers, too?

I've used MultiAnswer for its larger functionality, allowing one answer to depend on another somehow (like entering f and g, f' and g' when using product or quotient rule) but I've also used it a couple times simply to allow answers in either order.  UnorderedAnswer looks like it would certainly be easier in that case.  
In reply to Chrissy Safranski

Re: Only last of several UNORDERED_ANS pairs works

by Davide Cervone -
Is this a good thing to use instead of MultiAnswer if the only thing we're trying to allow is 2 answers, entered in either order?

Yes, it is a reasonable alternative to MultiAnswer in that case, although it does call the answer checkers more than once, and not all answer checkers work well that way.

Does it work for more answers, too?

Yes, it works with arbitrarily many answer checkers, so that is certainly more convenient than MultiAnswer when you have three or more answers to check.

The down side is that UNORDERED_ANS is not quite as robust (as is pointed out by the difficulty experienced in this question), so you have to be a little more careful when using it. As I said, it was a pretty early macro package, and probably could be improved were I to write it today.
In reply to Davide Cervone

Re: Only last of several UNORDERED_ANS pairs works

by Joel Trussell -
I've had reasonable success with unordered answers for problems like complex roots of complex numbers, the terms in a partial factor expansion  (this allows checking the terms to makes the student has the terms right, instead of checking the sum of the terms for correctness.