I am wanting to force students to simplify an expression like log_2(4) to be 2. Otherwise I have been able to force students to fully expand the logarithm. I feel like it should be a fairly easy fix (and I may have overlooked it), but I have been unable thus far to figure it out.
Here is what I have:
########################################################################
DOCUMENT();
loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"PGML.pl",
"answerHints.pl",
"PGML.pl",
"PGcourse.pl",
"parserFunction.pl",
);
# Print problem number and point value (weight) for the problem
TEXT(beginproblem());
# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;
##############################################################
#
# Setup
#
#
Context("Numeric")->flags->set(reduceConstantFunctions=>1);
Parser::Number::NoDecimals();
##y is ln(base1), z is ln(base2)
Context()->variables->add(x=>'Real',y=>'Real',z=>'Real');
Context()->variables->set(x=>{limits=>[2,3]},y=>{limits=>[2,3]},z=>{limits=>[2,3]});
parserFunction("log2(x)" => "log(x)/log(2)");
$power1 = 2;
$power2 = 3;
$power3 = 1;
$coef = 4;
$base = Formula("log2((x**$power1 y**$power2)/($coef*z**$power3))")->reduce;
#$base2 = $base**$power3;
$ans = Formula("$power1 * log2(x) + $power2 * log2(y) - log($coef)/log(2) - $power3*log2(z)")->reduce;
Context()->operators->undefine("/","^","**");
ANS($ans->cmp());
##############################################################
#
# Text
#
#
BEGIN_PGML
Expand the logarithm.
>> [`` [$base] ``] <<
The expanded form is [_______________]
Your answer should use [`` \log_2 (x) ``] but you need to enter it as [`` log2(x) ``].
END_PGML
##############################################################
#
ENDDOCUMENT();