WeBWorK Problems

Empty Set as Student Answer

Empty Set as Student Answer

by Paul Seeburger -
Number of replies: 3
I am trying to edit a set intersection/union problem to allow students to enter the empty set "{ }" as the answer when the intersection is empty.  The problem currently asks for "None" to be entered, which I do not find helpful for teaching students the notation of an empty set.

I used the following code to get set up this answer, which displays the correct answer correctly, but when you enter the correct answer as "{}" you are told this is incorrect and "Empty Parentheses" is the feedback.

Context("Interval");
$ans_a = Set();
ANS($ans_a->cmp());

Thanks for any help!

Paul
In reply to Paul Seeburger

Re: Empty Set as Student Answer

by Davide Cervone -
The following
Context("Interval");
$S = Set();

Context()->texStrings;
BEGIN_TEXT
\($S\) = \{$S->ans_rule\}
END_TEXT
Context()->normalStrings;

ANS($S->cmp);
correctly accepts {} for me. Can you give the complete problem you are working on? Also, what version of pg and webwork are you using?
In reply to Davide Cervone

Re: Empty Set as Student Answer

by Paul Seeburger -
Here's the whole problem, Davide.  I tried to implement your notation as closely as I could, still with the same results.  The empty set '{}' is still not accepted as the correct answer.

I'm using  ww_version: 2.8, pg_version: 2.8.1.

##DESCRIPTION
## Compound Inequalities
## 
##ENDDESCRIPTION
# Original Problem Author: Modified by Shafiu Jibrin 
#                 from setSets/ur_st_1_2.pg 
# Location: Northern Arizona University
## DBsubject(Set theory)
## DBchapter(Basic properties and operations)
## DBsection(Union and intersection)
## Institution(The College of Idaho)
## Author(RA Cruz)
## Level(2)
## TitleText1('Essentials of Intermediate Algebra')
## AuthorText1('Blitzer')
## EditionText1('1')
## Section1('4.1')
## Problem1('')
## KEYWORDS('inequalities')
## Date: 2007/10

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(
  "PGstandard.pl",
  "PGchoicemacros.pl",
  "MathObjects.pl",
#  "PGgraphmacros.pl",
#  "PGnauGraphics.pl",
#  "contextInequalitiesAllowStrings.pl",
  "answerHints.pl",
#  "CofIdaho_macros.pl"
);

TEXT(beginproblem());

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

@slice = NchooseK(12,9);
@A = ($slice[1], $slice[2], $slice[3], $slice[4]);
@B = ($slice[5], $slice[6], $slice[8]);
$AiB = "N";
@AuB = ($slice[1], $slice[2], $slice[3], $slice[4], $slice[5], $slice[6],$slice[8]);

for ($k=3; $k>0; $k-=1) {
  for ($i=0; $i<$k; $i+=1){
    if($A[$i]>$A[$k]) {
       $b = $A[$i];
       $A[$i] = $A[$k];
       $A[$k] = $b;
    }
  }
}

for ($k=2; $k>0; $k-=1) {
  for ($i=0; $i<$k; $i+=1){
    if($B[$i]>$B[$k]) {
       $b = $B[$i];
       $B[$i] = $B[$k];
       $B[$k] = $b;
    }
  }
}


#for ($k=2; $k>0; $k-=1) {
#  for ($i=0; $i<$k; $i+=1){
#    if($AiB[$i]>$AiB[$k]) {
#       $b = $AiB[$i];
#       $AiB[$i] = $AiB[$k];
#       $AiB[$k] = $b;
#    }
#  }
#}

for ($k=6; $k>0; $k-=1) {
  for ($i=0; $i<$k; $i+=1){
    if($AuB[$i]>$AuB[$k]) {
       $b = $AuB[$i];
       $AuB[$i] = $AuB[$k];
       $AuB[$k] = $b;
    }
  }
}

$LEFT_BRACE = '\{';
$RIGHT_BRACE = '\}';
 
Context("Interval");
$ans_a = Set();

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

Context()->texStrings;
BEGIN_TEXT

Let \( A= ${LEFT_BRACE} $A[0],  $A[1], $A[2], $A[3] ${RIGHT_BRACE}\) , $SPACE
\( B= ${LEFT_BRACE} $B[0],  $B[1],  $B[2] ${RIGHT_BRACE}\)
$BR
Find the following sets in list form. Separate elements with commas.  If there are no elements in the set, enter "NONE".
$PAR
a) \( A \cap B =  \) \{$ans_a->ans_rule(25) \}
$PAR
b) \( A \cup B = \) \{ans_rule(25)\} 
END_TEXT
Context()->normalStrings;
######################################
#  Answer


ANS($ans_a->cmp);

Context()->parens->replace('{' => {close => '}', type => 'Set'});

# $ans_a = String("NONE");

#ANS($ans_a->cmp->withPostFilter(AnswerHints(
#            sub {
 #              my ($correct,$student,$ans) = @_;
  #              if ($student=~ /\w/) {return $student !~ /[}{]/;}
   #             } => ["Enter your answer with set notation: { ... }", 
    #                  checkCorrect => 1, 
     #                 score => 0]
#)));

$ans_b = Set("{$AuB[0],$AuB[1],$AuB[2],$AuB[3],$AuB[4],$AuB[5],$AuB[6]}");
#Answer hints not working
ANS($ans_b->cmp->withPostFilter(AnswerHints(
            sub {
                my ($correct,$student,$ans) = @_;
                return $student !~ /[}{]/;
                } => ["Enter your answer with set notation: { ... }", 
                      checkCorrect => 1, 
                      score => 0]
)));

$showPartialCorrectAnswers = 1;

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


COMMENT('MathObject version');
ENDDOCUMENT();
In reply to Paul Seeburger

Re: Empty Set as Student Answer

by Davide Cervone -
OK, you left out of your original message the crucial information that you had redefined the open brace using
   Context()->parens->replace('{' => {close => '}', type => 'Set'});
which is the source of the problem. You want
   Context()->parens->replace('{' => {close => '}', type => 'Set', emptyOK=>1});
to allow empty braces to be allowed.

I'm not sure why you are redefining the braces, ass this new definition (with emptyOK should be exactly what is already in the Interval context, so I'd recommend removing the line entirely. If you way what you are trying to accomplish, I may be able to suggest an alternative.