[:: expression ::]**does reduce the formula. But you haven't used that, you have done
[$fp0]**, which is a different thing entirely. The first is a typeset expression given initially in algebra notation (indicated by the double colons), and the second is the (untypeset) string value of a variable (indicated by the dollar sign).
The meaning of stars following a PGML formatting directive like
[:: ... ::] or
[$...] depends on the directive itself, and they have different meanings for different directives. For example, after an answer blank (
[_____]), a star means use an answer array for matrices (and vectors, points, lists, etc.), while after a variable substitution (
[$...]) a star means use the value verbatim rather than quoting HTML and LaTeX special characters, as is usually done.
Because an algebra expression (
[:: ... ::]) is turned into a MathObject automatically by PGML (outside of your control), you can't use the
reduce() method on it yourself. So PGML gives you the double-star notation to make that possible as an option. On the other hand, when you are doing a variable substitution (
[$...]) there is no reason that the variable has to hold a MathObject, and if it is, that it is a Formula object, so using the double-star for formula reduction doesn't make sense in that case.
Furthermore, if you want the value of a variable holding a formula to be reduced, you could call its
reduce method within the variable substitution itself:
[$fp0->reduce]Since you have this option, there is no need for the double-star notation, whereas for
[:: ... ::], there is no such possibility, so the double-star notation is needed.
Alternatively, you could perform the reduction at the time the variable is created. For example, in your case, you could do
$fp0 = Formula("($a*$c*x + $b)/($c*x + $c*$d)")->reduce; ## f(x)so that
$fp0is reduced to begin with.
There is another advantage of this, in that you can use it in LaTeX portion of the problem text as well:
Given the rational function [``f(x) = [$fp0]``]rather than typing out the LaTeX version of the function again by hand. That is one of the purposes of MathObjects: you don't have to keep repeating the formulas in different formats.
First, when you do
$va = Formula("(-$d)"); ## Vertical asymptote $sa = Formula("($a)"); ## Horizontal Asymptoteyou are creating constant-values formulas, where you probably just want constants. With formulas, your students may get inappropriate error messages in some cases, as we talked about this week. Also, the parentheses are unneeded, here. Even the quotation marks are not needed, since MathObjects can convert a perl real into a MathObject Real. So I'd recommend
$va = Compute(-$d); ## Vertical asymptote $sa = Compute($a); ## Horizontal Asymptoteor just
$va = Real(-$d); ## Vertical asymptote $sa = Real($a); ## Horizontal Asymptotefor these.
Second you don't need the stars after the answer blanks, since these are not matrix, vector, or point-valued answers. The plain answer blanks are fine.
Third, you don't need to use display-style math for things like "x" and "f(x)", so
[`x`] is sufficient.