RestrictedStudentAnswers
Restricting Allowed Student Answer Formats: PG Code Snippet
This PG code shows how to check student answers that are equations. Note that this is an insertion, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.
In general, there are a number of different restrictions that one might want to place on a student answer: that it be completely simplified, that it be exact, etc. In the following we consider a number of these. Note that there are often many ways to accomplish the same goals, and the method suggested here may or may not be directly applicable to the case you are considering. Often using a Custom Answer Checker or setting a Custom Error Message will also be desirable.
Examples below:
 #Requiring that an answer be simplified to a constant
 #Requiring that an answer be a simplified fraction
 To require that a student answer be simplified to a polynomial, we can use the LimitedPolynomial Context, described on the Restricting Functions and Operators in Student Answers page
 ...other examples should be added here
Requiring that an answer be simplified to a constant
PG problem file  Explanation 

Context("Numeric"); $expr = Formula("sin(x)^2 + cos(x)^2"); $deriv = Compute(0); 
Setup:
The set up section has nothing out of the ordinary. Our variable

BEGIN_TEXT Find and simplify completely: $BR \(\frac{d}{dx}\left($expr\right) = \) \{ ans_rule(25) \} END_TEXT 
Main Text: The problem text section of the file is as we'd expect. 
$showPartialCorrectAnswers = 1; ANS( $deriv>cmp(showTypeWarnings=>0) ); ENDDOCUMENT(); 
Answer Evaluation:
Here we've turned off type warnings in the answer checking,
so that a student entering an unsimplified answer (e.g.,

Requiring that an answer be a simplified fraction
PG problem file  Explanation 

DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "contextFraction.pl", ); TEXT(beginproblem()); 
Initialization: We need to include the macro file

Context("FractionNoDecimals"); Context()>operators>undefine('+','','*', '*','**','^'); $a = random(2,4,1); $b = random(1,9,1); $c = random(1,9,1); $den = $c + $a*$a; $frac = Compute("$b/$den"); 
Setup:
Here we specify that we are using the
Note that because we've undefined these operators for
all MathObjects, we can't define the answer as
Also note that by default a Fraction will be reduced to lowest terms. 
BEGIN_TEXT Find and simplify completely the value of \(f($a)\) if \[ f(x) = \frac{$b}{$c + x^2}. \] $BR \(f($a) = \) \{ ans_rule(25) \} $BR ${BITALIC}(Simplify your answer as much as possible, and enter a fraction instead of a decimal.)$EITALIC END_TEXT 
Main Text: The problem text section of the file is as we'd expect. 
$showPartialCorrectAnswers = 1; ANS( $frac>cmp(studentsMustReduceFractions=>1, strictFractions=>1,strictMinus=>1, strictMultiplication=>1) ); ENDDOCUMENT(); 
Answer Evaluation: In the answer evaluation, we require students to reduce fractions, and by setting the remaining three flags, that the fraction be an integer over another integer. 
 POD documentation: [contextFraction.pl]
 PG macro: [contextFraction.pl]