DOCUMENT(); loadMacros('PGstandard.pl', 'MathObjects.pl', 'PGML.pl', 'contextLimitedPowers.pl', 'answerHints.pl', 'PGcourse.pl'); # Setup LimitedPowers::OnlyPositiveIntegers(); $var = list_random('a', 'b', 'x', 'y'); Context()->variables->are($var => 'Real'); $n = random(2, 4); $m = random(-9, -5); $num1 = random(2, 5); $num2 = random(-5, -2); $ans = Compute("$num1 * $num2 / $var^(-$n - $m)")->reduce; $ans_cmp = $ans->cmp->withPostFilter(AnswerHints( sub { my ($correct, $student, $ansHash) = @_; # Count the number of variables (Better if checked for reduced constants too.) my $CorrectVariableNumber = $correct =~ tr/a-zA-Z//; my $StudentVariableNumber = $student =~ tr/a-zA-Z//; return $ansHash->{score} == 1 && $CorrectVariableNumber < $StudentVariableNumber; } => [ 'Simplify your answer.', checkCorrect => 1, score => 0 ] )); # Main text BEGIN_PGML Simplify the expression: [`([$num1] [$var]^{[$n]})([$num2] [$var]^{[$m]}) =`] [_]{$ans_cmp} END_PGML ENDDOCUMENT();