## DESCRIPTION ## Algebra: algebraic fraction answer requiring simplification ## ENDDESCRIPTION ## KEYWORDS('algebra', 'algebraic fraction answer') ## DBsubject('WeBWorK') ## DBchapter('WeBWorK Tutorial') ## DBsection('Fort Lewis Tutorial 2011') ## Date('01/30/2011') ## Author('Paul Pearson') ## Institution('Fort Lewis College') ## TitleText1('') ## EditionText1('') ## AuthorText1('') ## Section1('') ## Problem1('') ########################### # Initialization DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGunion.pl", "parserMultiAnswer.pl", "PGcourse.pl", ); TEXT(beginproblem()); ########################## # Setup Context("Numeric")->variables->are(y=>"Real"); Context()->{error}{msg}{"Operands of '*' can't be words"} = " "; $a = random(2,8,2); $b = random(3,9,2); $c = random(1,9,1); while ($c == $b/$a) { $c = random(1,9,1); } $fraction = "\frac{$a y}{y-$c} + \frac{$b}{$c - y} "; $num = Formula("$a y - $b"); $den = Formula("y - $c"); $numbogus = Formula("$a*y+$b"); $denbogus = Formula("(y-$c)*($c-y)"); $multians = MultiAnswer($num, $den)->with( singleResult => 0, allowBlankAnswers => 1, checker => sub { my ( $correct, $student, $self ) = @_; my ( $f1stu, $f2stu ) = @{$student}; my ( $f1, $f2 ) = @{$correct}; if ( ( $f1==$f1stu && $f2==$f2stu) || (-$f1==$f1stu && -$f2==$f2stu) ) { return [1,1]; } elsif ( $f1==$f1stu || -$f1==$f1stu) { return [1,0]; } elsif ( ($numbogus==$f1stu || -$numbogus==$f1stu) || ($denbogus==$f2stu || -$denbogus==$f2stu) ) { $self->setMessage(1,"Find a common denominator first"); $self->setMessage(2,"Find a common denominator first"); return [0,0]; } elsif ( $f2==$f2stu || -$f2==$f2stu ) { return [0,1]; } elsif ( $f1*$f2stu==$f1stu*$f2 ) { $self->setMessage(1,"Simplify your answer further"); $self->setMessage(2,"Simplify your answer further"); return [0,0]; } else { return [0,0]; } } ); # # Display the fraction and answer blanks nicely # Context()->texStrings; if ($displayMode eq 'TeX') { $showfraction = "\[ $fraction = ".$multians->ans_rule(10).$multians->ans_rule(10)." \]"; } else { $showfraction = ColumnTable( "\( \displaystyle $fraction = \)", $multians->ans_rule(20).$BR.$HR.$multians->ans_rule(20), indent => 0, separation => 10, valign => "MIDDLE" ); } Context()->normalStrings; ################################# # Main text Context()->texStrings; BEGIN_TEXT Perform the indicated operations. Express your answer in reduced form. $BR $BR $BCENTER $showfraction $ECENTER END_TEXT Context()->normalStrings; ################################# # Answer evaluation $showPartialCorrectAnswers = 1; install_problem_grader(~~&std_problem_grader); ANS( $multians->cmp() ); ################################# # Solution Context()->texStrings; BEGIN_SOLUTION ${PAR}SOLUTION:${PAR} Solution explanation goes here. END_SOLUTION Context()->normalStrings; COMMENT('MathObject version.'); ENDDOCUMENT();