I have run into an issue. I am working on authoring questions that use the algebra of functions (and later composition of functions). I currently am not as concerned about students simplifying (though I may change on that), but I want the answers that they see to be the simplified version.
For instance, perhaps I am adding/subtracting/dividing/multiplying rational functions. Is there a way to define the functions (I am currently using formula), say as f and g, and then do f+g simplified.
Ideally this would also work for cases where there is no reasonable simplification as well like adding a polynomial and radical expression together.
What I have is included below. It accepts the simplified and unsimplified version (as they are equivalent formulas).
Thank you!
DOCUMENT();
loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"PGML.pl",
"contextLimitedPolynomial.pl",
);
# Print problem number and point value (weight) for the problem
TEXT(beginproblem());
# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;
######
Context("Numeric");
Context()->noreduce('(-x)-y','(-x)+y');
$f = Formula("3/(x^2 -x -2)")->reduce;
$g = Formula("-5/(x^2 -4)")->reduce;
$fPlusg = Formula("$f+$g")->reduce;
$gMinusf = Formula("$g-$f")->reduce;
$fTimesg = Formula("$f*$g")->reduce;
$fByg = Formula("$f/$g")->reduce;
##############################################################
BEGIN_PGML
Consider [` f(x) = [$f] `] and [` g(x) = [$g] `].
a. What is the sum of [`f(x)`] and [`g(x)`]?
[`(f+g)(x) = `][_____________________________]{$fPlusg}
b. What is the difference of [`f(x)`] from [`g(x)`]?
[`(g-f)(x) = `][_____________________________]{$gMinusf}
c. What is the product of [`f(x)`] and [`g(x)`]?
[`(fg)(x) = `][_____________________________]{$fTimesg}
d. What is the quotient of [`f(x)`] by [`g(x)`]?
[`\left(\dfrac{f}{g}\right)(x) = `][_____________________________]{$fByg}
END_PGML
ENDDOCUMENT();