## WeBWorK Problems

### Feedback issue on set and compound statement ### Feedback issue on set and compound statement

by Paul Seeburger -
Number of replies: 2
Hello!

I am having trouble getting the following feedback when using bizarroArithmetic to check for unreduced fractions in solution sets, like {2/6, 3} or compound statements, like: n = 2/6 or n = 3. For some reason it is telling the student that both numbers need to be simplified, when only one of them is unreduced.

Here's the feedback for the above answers. It's the same for both versions.

There is a problem with your first number:
There is a problem with your second number:

Is there a way I can adjust the checker to respond correctly?

Thanks!

Here is the code:

## DESCRIPTION
## Algebra: Fractional equations
## ENDDESCRIPTION

## Paul added multiple steps to this problem.
## DBsubject(Algebra)
## DBchapter(Rational equations and functions)
## DBsection(Rational equations)
## Date(11/14/2014) ## Created 10/26/2009
## Institution(University of Minnesota, Monroe Community College)
## Author(Jonathan Rogness, Paul Seeburger)
## Level(2)
## TitleText1('Algebra for College Students')
## AuthorText1('Kaufmann, Schwitters')
## EditionText1('8')
## Section1('4.6')
## Problem1('15')
## KEYWORDS('algebra', 'fractional equations')

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

DOCUMENT();

"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"compoundProblem5.pl",
"contextInequalitiesAllowStrings.pl",
"contextFraction.pl",
"bizarroArithmetic.pl",
"contextLimitedFactor.pl",
#"source.pl", # allows code to be displayed on certain sites.
"PGcourse.pl" # Customization file for the course
);

########################################################################
$scaffold = Scaffold(); #$isInstructor = ($envir{effectivePermissionLevel} >=$envir{ALWAYS_SHOW_SOLUTION_PERMISSION_LEVEL});
$isInstructor=0; # This variable changes what the user can see. INITIALIZE_SCAFFOLD('$scaffold');

TEXT(beginproblem());

$showPartialCorrectAnswers = 1; ######################################################################## Context("Numeric"); Context()->variables->are(n=>'Real'); Context()->strings->add(none=>{},EmptySet=>{alias=>"none"});$a = random(2,5,1);

$b = Compute("$a*$a+1");$lhs = Compute("n+1/n");

$LCD = Compute("$a n");

$lhs2 = Compute("$a n^2 + $a");$rhs2 = Compute("$b n");$extr = Compute("None");

$an2 = Compute("$a");

Context("Fraction");
Parser::Number::NoDecimals;
Context()->operators->set(
'/' => {class => 'bizarro::BOP::divide', isCommand => 1},
'//' => {class => 'bizarro::BOP::divide', isCommand => 1},
' /' => {class => 'bizarro::BOP::divide', isCommand => 1},
'/ ' => {class => 'bizarro::BOP::divide', isCommand => 1},
);
Context()->flags->set(
reduceConstants=>0, # no decimals
reduceConstantFunctions=>1, # combine 4+5*2?
);

$an1 = Fraction(1,$a)->reduce;

Context("Inequalities-AllowStrings");
Context()->variables->are(n=>'Real');
Parser::Number::NoDecimals;
Context()->operators->set(
'/' => {class => 'bizarro::BOP::divide', isCommand => 1},
'//' => {class => 'bizarro::BOP::divide', isCommand => 1},
' /' => {class => 'bizarro::BOP::divide', isCommand => 1},
'/ ' => {class => 'bizarro::BOP::divide', isCommand => 1},
);
Context()->flags->set(
reduceConstants=>0, # no decimals
reduceConstantFunctions=>1, # combine 4+5*2?
);

$possols = Compute("n =$an1 or n = $an2"); #$possols = Compute("n = 1/$a or n =$an2");

$solset = Compute("{1/$a, $a}"); Context("LimitedFactor"); Context()->variables->are(n=>'Real'); Context()->noreduce('(-x)-y','(-x)+y');$factored = Formula("($a n - 1)*(n -$a)");

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

Context()->texStrings;
BEGIN_TEXT
Solve the equation: $SPACE$SPACE$SPACE $$\large \displaystyle {lhs = \frac{b}{a}}$$$PAR
$PAR END_TEXT DISPLAY_SECTION( { name=>"1. Determine the LCD of the fractions in the equation", canshow =>1, #always true iscorrect=>$scaffold->requireCorrect(1),
section=>1 #designates that this is the first section
} , <<'END_SECTION');

$PAR LCD = \{SECTION_ANS($LCD->cmp), $LCD->ans_rule(10)\} END_SECTION Context()->normalStrings; ############ ## Section 2 ############ Context()->texStrings; DISPLAY_SECTION( { name=>"2. Clear the fractions", canshow =>$scaffold->requireCorrect(1). " or $isInstructor", iscorrect=>$scaffold->requireCorrect(2,3),
section=>2
}, <<'END_SECTION');
$PAR Multiply both sides of the equation by this LCD and simplify each side to cancel the denominators.$BR $BR $$\displaystyle {a n \cdot \left( lhs \right) = a n \cdot \frac{b}{a}}$$$BR $BR Enter the resulting expressions you obtain on each side of the equation.$BR $BR \{ans_rule(10)\} = \{ans_rule(10)\} END_SECTION Context()->normalStrings; SECTION_ANS($lhs2->cmp, $rhs2->cmp); ############## # Section 3 ############## Context()->texStrings; DISPLAY_SECTION( { name=>"3. Rewrite the equation, solve by factoring, and check answers", canshow =>$scaffold->requireCorrect(2,3). " or $isInstructor", iscorrect=>$scaffold->requireCorrect(6),
section=>3
}, <<'END_SECTION');

Rewrite this equation so that it is equal to zero, and the left side has a positive leading coefficient. Then factor the left side. $PAR \{ANS($factored->cmp), $factored->ans_rule(15) \} $$= 0$$$PAR
Solving this equation gives what possible solutions? Enter your answers in the form: $$n =$$ ______ or $$n =$$ ______
$PAR \{ SECTION_ANS($possols->cmp(
checker=>sub{
my ( $correct,$student, $ansHash ) = @_; return 0 if$ansHash->{isPreview};
$student =$ansHash->{student_formula};
$correct =$ansHash->{correct_ans};
$student = Formula("$student"); $correct = Formula("$correct");
return 0 unless ($correct ==$student);
Context()->flags->set(bizarroDiv=>1);
delete $correct->{test_values},$student->{test_values};
my $OK = (($correct == $student) or ($student == $correct)); Context()->flags->set(bizarroDiv=>0); Value::Error("Your answer is correct, but please simplify it further") unless$OK;
return $OK; })),$possols->ans_rule(30) \}
$PAR Which of these possible solutions are extraneous (because they make the equation undefined)?$BR
If none are, enter $BBOLD None$EBOLD. \{ SECTION_ANS($extr->cmp),$extr->ans_rule(10) \}
$PAR Finally, the solution set is: \{SECTION_ANS($solset->cmp(
checker=>sub{
my ( $correct,$student, $ansHash ) = @_; return 0 if$ansHash->{isPreview};
$student =$ansHash->{student_formula};
$correct =$ansHash->{correct_ans};
$student = Formula("$student"); $correct = Formula("$correct");
return 0 unless ($correct ==$student);
Context()->flags->set(bizarroDiv=>1);
delete $correct->{test_values},$student->{test_values};
my $OK = (($correct == $student) or ($student == $correct)) ; Context()->flags->set(bizarroDiv=>0); Value::Error("Your answer is correct, but please simplify it further") unless$OK;
return $OK; },showHints=>0)),$solset->ans_rule(15) \}
END_SECTION
Context()->normalStrings;

# \{ans_rule(15) \} $$= 0$$
# \{SECTION_ANS($factored->cmp),$factored->ans_rule(15) \} $$= 0$$
# ANS($factored->cmp()); #SECTION_ANS($factored->cmp(), $extr->cmp()); ############## # Section 4 ############## #Context()->texStrings; #DISPLAY_SECTION( #{ name=>"4. Solve the equation for the possible solutions", # canshow =>$scaffold->requireCorrect(4,5). " or $isInstructor", # iscorrect=>$scaffold->requireCorrect(6),
# section=>4
#}, <<'END_SECTION');

#Finally, the solution set is:
#\{SECTION_ANS($solset->cmp),$solset->ans_rule(15) \}
#END_SECTION
#Context()->normalStrings;

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

$last_correct_section = PROCESS_SECTIONS();$opensection = $last_correct_section + 1; for ($i = 1; $i<=$opensection; $i++) {$scaffold->openSections($i); } TEXT($END_ONE_COLUMN);
ENDDOCUMENT(); ### Re: Feedback issue on set and compound statement

by Paul Seeburger -
I was able to find a way to get the compound assignment statement to work properly using code from the PCC problems (see below), but I still am not able to get it to work for the solution sets {2/6, 3}.  Basically, it appears that I just don't know the parameters well enough to adjust this code to work with it correctly.  Anyone able to help with this part?

Thanks!

Paul

Context("LimitedFraction")->flags->set(reduceFractions => 0);
Context()->variables->are(n=>'Real');
parser::Assignment->Allow;
Context()->operators->redefine(',',using=>',',from=>'Numeric');
Context()->operators->redefine('or',using=>',',from=>'Numeric');
Context()->operators->set(
','=>{string=>' or ',TeX=>'\hbox{ or }'},
'or'=>{string=>' or ',TeX=>'\hbox{ or }'}
);
Context()->lists->set(List => {separator => " or "});

$an1 = Fraction(1,$a)->reduce;
$an2 = Fraction($a,1);
$possols = Compute("n =$an1 or n = $an2"); and later: ANS($possols->cmp(  entry_type => "a solution",
checker => sub {
my ($correct,$student,$ans,$nth,$value) = @_; if ($correct->type eq "Assignment") {
my ($svar,$sfrac) = $student->value; # get the variable and fraction #return 0 unless Value::classMatch($sfrac,'Fraction') && $sfrac->isReduced; if(Value::classMatch($sfrac,'Fraction'))
{
return 0 unless $sfrac->isReduced; } } return$correct == $student; }, extra => sub { my ($student,$ansHash,$nth,$value) = @_; if($student eq "No solution")
{
$student->context->setError("This equation does have some solutions- look back at your work","",undef,undef,$Value::CMP_WARNING)
unless $ans->{isPreview}; return; } if ($student->type ne "Assignment" && $ansHash->{student_formula}->type ne "Assignment") {$student->context->setError("Your $nth solution should be written n =$US$US$US","",undef,undef,$Value::CMP_WARNING) unless$ans->{isPreview};
return;
}
my ($svar,$sfrac) = $student->value; # get the variable and fraction if (Value::classMatch($sfrac,'Fraction') && !$sfrac->isReduced) {$student->context->setError("Your $nth$value is not reduced","",undef,undef,$Value::CMP_WARNING) unless$ans->{isPreview};
return;
}
return Value::Real->typeMatch($student); } )) In reply to Paul Seeburger ### Re: Feedback issue on set and compound statement by Paul Seeburger - I think I have this problem solved now! It came down to using a combination of bizarroArithmetic and a list_checker. Before I had been checking each element of the set one at a time and it was causing trouble by claiming that even non-fractions were unsimplified when the answer was not working (see my first question in this thread). Here is the checker I used for the solution set: \{SECTION_ANS($solset->cmp(entry_type => "a solution",
list_checker => sub {
my ($correct,$student,$ansHash,$value) = @_;
my $n = scalar(@$student);  # number of student answers
my $score = 0; # number of correct student answers return 0 if$ansHash->{isPreview};
$student =$ansHash->{student_formula};
$correct =$ansHash->{correct_ans};
$student = Formula("$student"); $correct = Formula("$correct");
return 0 unless ($correct ==$student);
Context()->flags->set(bizarroDiv=>1);
delete $correct->{test_values},$student->{test_values};
my $OK = (($correct == $student) or ($student == $correct)) ; Context()->flags->set(bizarroDiv=>0); Value::Error("Your answer is correct, but please simplify it further.") unless$OK;
if ($OK) {$score = $n}; return$score;
}
))

To remind you, here is how I had defined the solutions $an1 and$an2 and $solset: Context("LimitedFraction")->flags->set(reduceFractions => 0);$an1 = Fraction(1,$a);$an2 = Fraction($a,1); Context("Inequalities-AllowStrings"); Context()->variables->are(n=>'Real'); Context()->strings->add("No solution"=>{NONE}); Parser::Number::NoDecimals; Context()->operators->set( '/' => {class => 'bizarro::BOP::divide', isCommand => 1}, '//' => {class => 'bizarro::BOP::divide', isCommand => 1}, ' /' => {class => 'bizarro::BOP::divide', isCommand => 1}, '/ ' => {class => 'bizarro::BOP::divide', isCommand => 1}, ); Context()->flags->set( reduceConstants=>0, # no decimals reduceConstantFunctions=>0, # combine 4+5*2? formatStudentAnswer=>'parsed', # no decimals );$solset = Compute("{$an1,$an2}");