## WeBWorK Problems

by Olivia Henders -
Number of replies: 2
What determines whether or not an answer gets reduced when it's displayed? In one problem (shown below), the answer displays as a "full" equation (no simplification), where in others, the answer gets simplified down to a single number. I know that using the reduce function can at least play a part in this, but I'm not using it anywhere. In fact, using it on the answer in the below example doesn't even change the answer, despite there being a coefficient of 1 in one place.

## DESCRIPTION
##
## ENDDESCRIPTION
## DBsubject()
## DBchapter()
## DBsection()

#############################################
# Initialization
DOCUMENT();
loadMacros(
 "PGstandard.pl",
 "MathObjects.pl",
 # Needed to support graph generation.
 "PGgraphmacros.pl",
 "unionTables.pl",
 # Used to provide contextual help for how to type answers.
 "AnswerFormatHelp.pl",
 # Provides greater control over the layout of the problem.
 "PGML.pl",
 # Used for course-specific initializations.
 "PGcourse.pl",
);
TEXT(beginproblem());
# Refreshes the graph image every time the page is loaded, as opposed to
# retrieving a cached version.
$refreshCachedImages = 1; ############################# # Setup Context("Numeric"); # Value initialization. $a = random(0,3,1);
$f = Compute("sqrt(x)+$a");
# Graph values
$minX = -5; $minY = -5;
$maxX = 5; $maxY = 5;
$originX = 0; $originY = 0;
$gridHoriz =$maxX-$minX; $gridVert = $maxY-$minY;
$shadedMinX = 1; $shadedMinY = 0;
$shadedMaxX = 4; $shadedMaxY = $f->eval(x=>$shadedMaxX);
# Converts $f to LaTeX for display later. $ftex = $f->TeX; # Calculates the value for the answer. $answer = Compute("(2/3) * (4^(3/2) - 1) + 3*$a"); # Initialize graph at the required size. $gr = init_graph($minX,$minY,$maxX,$maxY,grid=>[$gridHoriz,$gridVert],axes=>[$originX,$originY],size=>[300,300]);
$gr->lb('reset'); # Initializes the x-axis positive and negative number labels. foreach my$i (1..$maxX-1) { $gr -> lb(new Label ( $i,-0.25,$i,'black','center','middle'));
}
foreach my $i (1..-$minX-1) {
 $gr -> lb(new Label (-$i,-0.25,-$i,'black','center','middle')); } # Initializes the y-axis positive and negative number labels. foreach my$i (1..$maxY-1) { $gr -> lb(new Label (-0.25,$i,$i,'black','center','middle'));
}
foreach my $i (1..-$minY-1) {
 $gr -> lb(new Label (-0.25,-$i,-$i,'black','center','middle')); } # Define new graph colors # Not all of these are used, but they are defined for easier use later. $gr->new_color("skyblue", 86,180,233); # RGB
$gr->new_color("darkskyblue", 38,79,233); $gr->new_color("orange", 230,159,0);
$gr->new_color("darkorange", 182, 58, 0); # # Choose colors # $light = "skyblue";
$dark = "darkskyblue"; # Graph the function and the filled region add_functions($gr, "$f for x in <0,5> using color:$dark and weight:4");
$gr->moveTo(1,$a+1);


# Draws lines below function line to form boundary of shaded area.
$gr->lineTo($shadedMinX,$shadedMinY,$dark,4);
$gr->lineTo($shadedMaxX,$shadedMinY,$dark,4);
$gr->lineTo($shadedMaxX,$shadedMaxY,$dark,4);
# Fills in area that needs to be shaded.
$gr->fillRegion([$shadedMinX + 0.1, $shadedMinY + 0.1,$light]
);
#############################
# Main Text
# Defines the problem text.
# Places the following information in column1 (the leftmost) of the layout table.
$column1 = PGML::Format(<<END_PGML); Use the graph to find the area of the shaded region under [f(x) =$ftex].
Area = [______________][@ AnswerFormatHelp("numbers") @]*
END_PGML
# Places graph image in right-hand column.
$column2 = image( insertGraph($gr),height=>300,width=>300,tex_size=>800 ).
$BR.$BCENTER.
$BR. "Graph of $$y = f(x)$$". $ECENTER;
TEXT(ColumnTable($column1,$column2, indent => 0, separation => 30, valign => "TOP"));
#############################
# Answer Evaluation

# Setting this to 1 means that students will receive feedback on whether their
# answers are correct.
$showPartialCorrectAnswers = 1; ANS($answer->cmp());
#############################
# Solution
BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION
COMMENT('Uses PGML. Looks like pi.');
ENDDOCUMENT();

by Gavin LaRose -

I'm not the expert on this, but here's a first stab at an explanation:

1. When using Compute("string"), the quoted string is reported verbatim as the correct answer when answer checking. Thus, something like Compute("(2/3) * (4^(3/2) - 1) + 3*$a") will report the string (2/3)*(4^(3/2)-1)+3*[the value of$a] as the correct answer.
2. However, if we know that the answer is a specific type (here, real), and define the answer as something like Real("(2/3) * (4^(3/2) - 1) + 3*\$a"), the answer will be reported as the decimal answer.
3. Reduce is a method available for MathObject Formulas, and does some reduction of constants, but is not a full computer algebra system. There is a wiki page on what it does here: http://webwork.maa.org/wiki/Reduction_rules_for_MathObject_Formulas.

Gavin