DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "contextLimitedPowers.pl", "PGML.pl" ); Context("Numeric"); LimitedPowers::OnlyPositiveIntegers(); TEXT(beginproblem()); # counts the number of occurances of $needle in $haystack sub count { my ($needle, $haystack) = @_; my $count = () = $haystack =~ /~~Q$needle~~E/g; return $count; } $var = "x"; $m = 4; $n = 9; $diff = $n - $m; $ans = Formula("1/$var^{$diff}"); $ans = $ans->cmp( checker => sub { my ($correct, $student, $self) = @_; my $str = $self->{original_student_ans}; Value->Error("Remember to simplify!") if count($var, $str) > 1; return $correct == $student; } ); BEGIN_PGML Simplify the following fraction without using negative exponents. [`\dfrac{[$var]^[$m]}{[$var]^[$n]} = `] [__]{$ans} END_PGML ENDDOCUMENT();