A similar idea would be to use an answer rule followed by the pi, so the student only enters the fraction, not the pi itself.
To really do what you are after, there are two possibilities, both rather difficult. One would be to write a post-filter that first checks if the answer is correct, and then analyzes the student's formula to see if it is of the correct form and is reduced. Such tests are notoriously hard to get right, as students can be quite varied in the way they format their answers.
The second is to develop a context in which only the type of answer you are interested in is syntactically correct. This is possible, but it is an advanced technique and not many know how to do it (maybe just me). To do that, you would have to really specify what is to be allowed in the answers. Would pi/2 + pi be acceptable, for example, or would it have to be 3pi/2? How about (1+2)pi/2? and so on.
[It also might be possible to abuse the LimitedPolynomial context to force an answer that looks like a pi /b, and combine that with a post-filter to check for reduced fractions, but it would be a bit awkward.]
In terms of your use of the
reduce
method, that does not reduce fractions in the form that you have them, as you have found out. MathObjects is not a full-features CAS, and the reduction rules are pretty rudimentary (mainly designed to make it easier to use random variables in formulas and still avoid things like "x + -3" or "1 x + 0".You could use the Fraction object to get a reduced fraction and then insert the results into a formula, or there is a
reduce()
function in PGauxiliaryFunctions.pl
that you could use to reduce a pair of integers.Davide