WeBWorK Problems

Answer is a list of sets

Answer is a list of sets

by Paul Pearson -
Number of replies: 1

Hi folks,


I would like to be able to assess answers that are sets and list of sets (perhaps even sets of sets).  The discussion https://webwork.maa.org/moodle/mod/forum/discuss.php?d=2950 points out one way to do accomplish this, but the answer checking is not doing what I would hope.  For instance, if the correct answer is the list of sets {A,B},{C,D} and a student enters {C,D},{A,B} then their answer will be marked correct (as expected), but if they enter {D,C},{A,B} their answer will be marked incorrect (not as expected).  The problem below and attached exhibits this behavior (using pg 2.12) using strings added to the context.  More generally, I would like to be able to do this using named matrices, permutations, etc., that have been added to the context (not just strings) because I am working on problems in abstract algebra (algebraic structures).

Thanks!

Paul


DOCUMENT();


loadMacros(

"PGstandard.pl",

"PGML.pl",

"contextArbitraryString.pl",

);

TEXT(beginproblem());


# https://webwork.maa.org/moodle/mod/forum/discuss.php?d=2950


Context("Numeric");

Context()->strings->add(

alpha => {caseSensitive => 1},

beta  => {caseSensitive => 1},

gamma  => {caseSensitive => 1},

delta  => {caseSensitive => 1},

);

Context()->parens->set("{" => {type => "List", removable => 0});


$answer1 = Compute("{alpha,beta,gamma}");


$answer2 = Compute("{alpha,beta}, {gamma,delta}");


BEGIN_PGML

# Answer is a set of strings or several sets of strings


Using set notation, what is the set of the first three letters of the Greek alphabet in their natural order? [__________________]{$answer1->cmp(list_type=>"set", removeParens=>0, implicitList=>0, showParenHints=>1, ordered=>1)}  Note: [| {beta, alpha, gamma} |] is marked incorrect (as expected).


Enter [| {alpha,beta}, {gamma,delta} |] [_____________________]{$answer2->cmp(list_type=>"set", removeParens=>0, implicitList=>0, showParenHints=>1)}  Note: [| {gamma,delta}, {alpha,beta} |] is marked correct, but [| {delta,gamma}, {alpha,beta} |] is not marked correct (not as expected).


END_PGML


ENDDOCUMENT();

In reply to Paul Pearson

Re: Answer is a list of sets

by Davide Cervone -

This discussion may be more applicable here, because it uses actual sets, not lists, as in your example.

For instance:

###########################
# Setup

$context = Context("Interval");

$context->flags->set(
  formatStudentAnswer => 'parsed',
  NumberCheck => sub {
    my $self = shift;
    $self->Error('Numbers are not allowed in this answer');
  }
);
$context->variables->clear;
$context->functions->disable('All');
$context->operators->undefine($context->operators->names);
$context->operators->redefine(',');
$context->strings->clear;
$context->parens->undefine('(','[');
$context->constants->clear;
$context->{cmpDefaults}{Set} = {cmp_class => "a set"};

@letters = ('alpha', 'beta', 'gamma', 'delta');
foreach $n (0..$#letters) {
  $context->constants->add($letters[$n] => $n);
  $context->constants->set($letters[$n] => {TeX => "\$letters[$n]"});
}

$answer2 = Compute("{alpha,beta}, {gamma,delta}");


###########################
# Main text

BEGIN_PGML

Enter [| {alpha,beta}, {gamma,delta} |] [_____________________]{$answer2}

END_PGML

Lets you enter the two sets in any order, with the elements in any order. You are not allowed to do any computations within the sets, however, so if your matrix or permutation questions need that sort of thing, then this won't work as is.

The Sets MathObject is fundamentally a set of Reals. It would be possible to make an object that is a set of more arbitrary elements, as long as the elements have a natural ordering. One could probably convert the current Set object implementation to such an arbitrary set without too much difficulty. you can probably get away without re-implementing the Union object since you don't need intervals and could just do finite set operations. you might need to do some subclassing in the Parser item classes as well, but it's been a while since I worked with them, so don't remember how abstract they are.