I am working on writing transformation of functions problems, so I am looking to display af(bx-c)+d with it automatically simplifying multiplications by 1 and adding zero.

The problem I am having is that my parenthesis are disappearing. It worked fine for 2f(x-1) but not if c=0.

The code I was using has (note that it is a static question but allows me to change values as I see fit or randomize it later if I want):

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"contextInequalitiesAllowStrings.pl",

"answerHints.pl",

"PGML.pl",

"PGcourse.pl",

"contextLimitedPoint.pl",

);

TEXT(beginproblem());

######################################

# Setup

$a = -1;

$b = 2;

$c = 0;

$d = 3;

$x1 = 0;

$y1 = 2;

$x2 = -5;

$y2 = 4;

$x3 = -2;

$y3 = 4;

$x4 = 2;

$y4 = 0;

$x5 = 5;

$y5 = 6;

Context ("Numeric");

Context ()->variables->add (f => 'Real');

Context()->noreduce('(-x)-y');

Context()->noreduce('(-x)-y','(-x)+y');

$transformation = Formula("$a f( $b x-$c)+$d")->reduce;

######################################

# Main text

BEGIN_PGML

Consider the graph (click on the image to make it larger):

>> [@image( "https://d1q29jrdo98n6g.cloudfront.net/embed/p5eee3fb1fcfb2871abe9d575/Transformations_Homework_Pic_1.jpg", width=>300, height=>150,

tex_size=>700, extra_html_tags=>'alt="Graph of a plot."' )@]*** <<

For the transformation [`` [$transformation] ``].

The point ([$x1],[$y1]) goes to the point [___________].

The point ([$x2],[$y2]) goes to the point [___________].

The point ([$x3],[$y3]) goes to the point [___________].

The point ([$x4],[$y4]) goes to the point [___________].

The point ([$x5],[$y5]) goes to the point [___________].

END_PGML

######################################

# Answer

Context("LimitedPoint");

$point1 = Point("(($x1 +$c)/$b,($a*$y1)+ $d)");

$point2 = Point("(($x2 +$c)/$b,($a*$y2)+ $d)");

$point3 = Point("(($x3 +$c)/$b,($a*$y3)+ $d)");

$point4 = Point("(($x4 +$c)/$b,($a*$y4)+ $d)");

$point5 = Point("(($x5 +$c)/$b,($a*$y5)+ $d)");

####tolerance included for later problems that include decimals so I have that option

ANS($point1->cmp(tolType => 'absolute',

tolerance => 0.00));

ANS($point2->cmp(tolType => 'absolute',

tolerance => 0.00));

ANS($point3->cmp(tolType => 'absolute',

tolerance => 0.00));

ANS($point4->cmp(tolType => 'absolute',

tolerance => 0.00));

ANS($point5->cmp(tolType => 'absolute',

tolerance => 0.00));

$showPartialCorrectAnswers = 1;