Answer Blank in the Exponent

Answer blank in the exponent

Complete Code

Download file: AnswerBlankInExponent.pg

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');

Preamble

These standard macros need to be loaded.
Context()->variables->are(a => 'Real', b => 'Real');

$n = random(3, 9);

# TeX
$expression = "a^{$n} b^{$n}";

# MathObjects
$base     = Formula("a*b");
$exponent = Formula("$n");

# Display exponents nicely
if ($displayMode eq 'TeX') {
    $exp =
        "\( \displaystyle $expression = ("
        . ans_rule(4) . ")^{"
        . ans_rule(4) . "}\)";
} else {
    $exp =
        "<span>\(\displaystyle $expression = \Big(\)"
        . ans_rule(4)
        . '\(\Big)\)</span><span style="vertical-align: 12pt;">'
        . ans_rule(4)
        . '</span>';
}

Setup

Set the context to allow only the variables a and b and choose a random exponent.

The exponential layout is in HTML using a pair of adjacent span elements with the right one shifted up using the CSS style vertical-align. In hardcopy mode, a LaTeX exponent is used.

BEGIN_PGML
Rewrite the following using a single exponent.

[$exp]*
END_PGML

Statement

Insert the exponential stored as $exp.

ANS($base->cmp);
ANS($exponent->cmp);

Answer

It is necessary to install the answer evaluator with ANS since ans_rule was used to produce answer blanks.

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.