# LimitedPowers

## Restricting Allowed Powers (Exponents) in Student Answers

This PG code shows how to restrict the allowed powers in student answers.

You may also be interested in other limited contexts DisableFunctions

PG problem file Explanation
```DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
"PGcourse.pl",
"contextLimitedPowers.pl",
);

TEXT(beginproblem());
```

Initialization: Use `contextLimitedPowers.pl` to restrict what is allowed as arguments to exponentiation `a^b`.

```Context("Numeric");

#LimitedPowers::NoBaseE();

#  chose one of these three:
#LimitedPowers::OnlyIntegers();
LimitedPowers::OnlyPositiveIntegers();
#LimitedPowers::OnlyNonNegativeIntegers();

\$a = random(2,5,1);
```

Setup: This is the section where we restrict the allowed types of powers. For more options, see the POD documentation contextLimitedPowers.pl

```Context()->texStrings;
BEGIN_TEXT
(a) Enter \( \$a^3 \): \{ ans_rule(10) \}
\$BR
(b) Enter \( 1/\$a^3 \), not \( \$a^{-3} \): \{ ans_rule(10) \}
\$BR
(c) Enter \( 1/x^2 \), not \( x^{-2} \): \{ ans_rule(10) \}
END_TEXT
Context()->normalStrings;
```

Main Text: The problem text section of the file is as we'd expect.

```\$showPartialCorrectAnswers = 1;

ANS( Real("\$a^3")->cmp() );
ANS( Real("1/\$a^3")->cmp() );
ANS( Compute("1/x^2")->cmp() );

ENDDOCUMENT();
```