DOCUMENT(); loadMacros( "PGstandard.pl", "contextFraction.pl", "PGML.pl" ); TEXT(beginproblem()); Context("LimitedFraction"); # randomize the base $base = random(-5,5,1); # to avoid undefined fractions do { $exp = random(-3,3,1); } until ($base != 0 || $exp > 0); # with a 50/50 chance of a leading negative $negative = random(0,1,1); # used to store the answer to the problem if ($base != 0) { $ans = (Fraction($base,1) ** $exp)->cmp(studentsMustReduceFractions => 1); } else { $ans = (Fraction($base,1) ** $exp); } # used to render the power in the problem statement $problem = "$base^{$exp}"; # if the base is negative, put brackets around it if ($base < 0) { $problem = "($base)^{$exp}"; } else { $problem = "$base^{$exp}"; } # make the power negative half the time if ($negative == 1) { $problem = "-$problem"; $ans = -$ans; } BEGIN_PGML Simplify the fraction [`[$problem]`]. Be sure to write your answer as a single fraction in lowest terms. Answer: [___]{$ans} END_PGML ENDDOCUMENT();