Hello, I am trying to use the Set class and I noticed that the answer checker will not mark the answer wrong if {} is missing. Is there a way to require {} in student's answer? Thank you.

DOCUMENT();

This forum has a limit to the number of forum postings you can make in a given time period - this is currently set at 10 posting(s) in 1 day

Hello, I am trying to use the Set class and I noticed that the answer checker will not mark the answer wrong if {} is missing. Is there a way to require {} in student's answer? Thank you.

DOCUMENT();

loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"PGML.pl",

"PGchoicemacros.pl",

"scaffold.pl",

"PGcourse.pl"

);

TEXT(beginproblem());

###########################

# Setup

Context("Interval");

@nums =(1..10);

@aNums = @nums[NchooseK(10, 6)];

@bNums = @nums[NchooseK(10, 4)];

$A = Set(@aNums);

$B = Set(@bNums);

$aString = join(", ", num_sort(@aNums));

$bString = join(",", num_sort(@bNums));

$AUB = Union("$A U $B");

###########################

# Main text

BEGIN_PGML

Let [`A = \{[$aString]\}, B = \{[$bString]\}. A \cup B = `] [______________________]

END_PGML

############################

# Answer evaluation

$showPartialCorrectAnswers = 1;

ANS( $AUB->cmp(

removeParens=>0,

implicitList=>0,

showParenHints=>1,

showLengthHints=>1,

requireParenMatch=>1,

));

ENDDOCUMENT();

The problem turns out to be in the Union answer checker (which uses the list checker internally, and ends up having accidentally bypassed the type checking that is usually performed).

One solution is to make sure that your checker is using a Set rather than a Union (since the union is a set). That can be done in several ways. Oner is to use `Set()`

rather than `Union()`

:

$AUB = Set("$A U $B");

Another would be to use the `reduce()`

method to simplify the union into a set:

$AUB = Union($A,$B)->reduce;

Another would be to use the overloaded `+`

operator, which acts as union on operands that are sets:

$AUB = $A + $B;

Any of this will result in `$AUB`

being a set rather than a union.

A couple of coding suggestions:

You don't need

`$aString`

and`$bString`

, as PGML will produce the proper output for sets. So you can useLet [`A = [$A]`], [`B = [$B]`]. Then [`A \cup B = `] [______________________]

I would recommend separate math delimiters for the three expressions above, rather than including the commas and periods within the math. The commas and periods are part of the sentence, not the math, and so it is inappropriate to include them in the math itself.

You don't need to use a separate

`ANS()`

call, but can just put the`$AUB`

in the PGML. None of the values you set are needed, here.Let [`A = [$A]`], [`B = [$B]`]. Then [`A \cup B = `] [______________________]{$AUB}

That should resolve your problem.

I tested all three solutions that you mentioned, for some reason, the first two check for {}, and third one does not. I will stick with the first two for now.

Also, I was able to remove the string variables and simplify the answer checking process.