## 2017 Problem Authoring Workshop

### Reducing coefficients of "1" and "0" in the problem display

by tim Payer -
Number of replies: 3
Hello again,

I recall from the Problem Authoring workshop 2, am session that we could reduce coefficients of 1 such that 1*x^2 would be displayed to the student as just x^2.

I thought that to achieve this we needed to place the expression within these square brackets such as this:
[:: expression :: ]**

and that this would permit this kind of reduction of 1*x^2 to x^2 in the problem display.

Unfortunately I must be using the wrong format for this, could you please explain what I have wrong here?

I have pasted a code block below that displays the problem...

Thanks for any help with this..

##DESCRIPTION
## Sign Analysis on a Rational Function

##KEYWORDS('sign analysis')

## DBsubject('Precalculus')
## DBchapter('Rational equations and functions')
## DBsection('Asymptotes')
## Date('6/7/2017')
## Author('Tim Payer')
# WeBWorK problem written by TimPayer <tsp1@humboldt.edu>
# ENDDESCRIPTION

DOCUMENT();

"PGstandard.pl",
"PGunion.pl",
"PGnumericalmacros.pl",
"PGstatisticsmacros.pl",
"MathObjects.pl",
"parserPopUp.pl",
"PGML.pl",
"unionTables.pl",
"niceTables.pl",
"PGcourse.pl",
"PGchoicemacros.pl",
);

#Text(beginproblem()); #uncomment

$showPartialCorrectAnswers = 1; Context("Numeric"); Context()->flags->set( tolerance => 0.01, tolType => "absolute", ); ############ Start Problem HW 1.5 #################$a = non_zero_random(-7,7);
$b = non_zero_random(-7,7);$c = random(2,7)*list_random(-1,1);
$c = Compute("1");$d = non_zero_random(-7,7);

$va = Formula("(-$d)"); ## Vertical asymptote
$sa = Formula("($a)"); ## Horizontal Asymptote
$fp0 = Formula("($a*$c*x +$b)/($c*x +$c*$d)"); ## f(x)$fp1 = Formula("($a*$c*$d-$b)/($c(x+$d)**2)"); # first derivative
$fp2 = Formula("2*($b-$a*$c*$d)/($c*(x+$d)**3)"); # second derivative if ($a*$d*$c*$c <$b*$c ) {$f1s = "dec";
$f2s = "dec";$d1s = "-";
$d2s = "-";$dd1s = "CD";
$dd2s = "CU"; } else {$f1s = "inc";
$f2s = "inc";$d1s = "+";
$d2s = "+";$dd1s = "CU";
$dd2s = "CD"; } ## Delete Below when done$cp1 = Compute("1");
$cp2 = Compute("1");$z1 = Compute("0");

### Row 2, f(x) is incresing or decreasing

$f1 = PopUp( ["?", 'inc', 'dec'],$f1s);
$f2 = PopUp( ["?", 'inc', 'dec'],$f2s);

### Row 3, f'(x) is positive or negative
$d1 = PopUp( ["?", '+', '-'],$d1s);
$d2 = PopUp( ["?", '+', '-'],$d2s);

### Row 4, f''(x) is positive with f(x) CU or f''(x) is negative with f(x) CD
$dd1 = PopUp( ["?", 'CU', 'CD'],$dd1s);

$dd2 = PopUp( ["?", 'CU', 'CD'],$dd2s);

#################### Begin Problem...#######################

BEGIN_PGML
*WeBWorK workshop 2017 HW 1.5)
A sign analysis for a rational function*

*HW 1.5)* Given the rational function [f(x) = \frac{[$a*$c]x +[$b]}{[$c]x + [$c*$d]}],
or this formula: [f(x)] = [fp0]** perform a sign analysis for the function and the first and second derivatives. Find all critical points and asymptotes associated with the function. *1.5a)* Find the vertical asymptote: [x] = [_______]* *1.5b)* Find the horizontal asymptote: [y] = [_______]* *1.5c)* Find the first derivative: [f'(x)] = [_______]* *1.5d)* Find the second derivative: [f''(x)] = [_______]* [@ DataTable( [ ['*1.5e)* Complete the table below for a correct sign analysis. Use the key at the right to enter the correct values for the function. Determine the signs of the function, and its first and second derivative before and after the vertical asymptote.', '','inc = f(x) is increasing. dec = f(x) is decreasing. + = f(x) is positive. - = f(x) is negative. CU = f^{\prime \prime}(x) > 0  and f(x) is concave up. CD = f^{\prime \prime}(x) < 0 and f(x) is concave down.' ], ], caption => ' ', midrules=>1, align => '|p{3in} p{0.2in}|p{3in}|' ); @]* END_PGML BEGIN_TEXT \{ DataTable( [ ['BBOLD 1.5e) $EBOLD Complete the table below for a correct sign analysis. Use the key at the right to enter the correct values for the function. Determine the signs of the function, and its first and second derivative before and after the vertical asymptote.', '','inc = $$f(x)$$ is increasing.$BR dec = $$f(x)$$ is decreasing. $BR + = $$f(x)$$ is positive.$BR - = $$f (x)$$ is negative. $BR CU = $$f^{\prime \prime}(x) > 0$$ and $$f(x)$$ is concave up.$BR CD = $$f^{\prime \prime}(x) < 0$$ and $$f(x)$$ is concave down.' ],
],
caption => ' ',
midrules=>1,
align => '|p{3in} p{0.2in}|p{3in}|'
);
\}
$PAR \{ DataTable( [ ['','Before the$BR vertical $BR asymptote:','Vertical$BR asymptote', 'After the $BR vertical$BR asymptote:' ],
['$$x =$$','',''.$va->ans_rule(2).'', '' ], ['$$f(x)$$',''.$f1->menu.'','$$\hspace {20pt} |$$',''.$f2->menu.'' ], ['$$f^\prime (x)$$',''.$d1->menu.'','$$\hspace {20pt} |$$',''.$d2->menu.'' ], ['$$f^{\prime \prime} (x)$$',''.$dd1->menu.'','$$\hspace {20pt} |$$', ''.dd2->menu.'' ], ], caption => ' ', midrules=>1, align => '|p{0.5in}|p{1in}| p{1in}|p{1in}|p{1in}|' ); \}PAR
END_TEXT

## Asymptotes and derivatives ##
WEIGHTED_ANS( ($va)->cmp, 1 ); WEIGHTED_ANS( ($sa)->cmp, 10 );
WEIGHTED_ANS( ($fp1)->cmp, 10 ); WEIGHTED_ANS( ($fp2)->cmp, 15 );

## HW 1.5e Sign Analysis Table: ##
###Row 1:
WEIGHTED_ANS( ($va)->cmp, 2 ); ###Row 2: WEIGHTED_ANS( ($f1)->cmp, 1 );
WEIGHTED_ANS( ($f2)->cmp, 1 ); ###Row 3: WEIGHTED_ANS( ($d1)->cmp, 1 );
WEIGHTED_ANS( ($d2)->cmp, 1 ); ###Row 4: WEIGHTED_ANS( ($dd1)->cmp, 1 );
WEIGHTED_ANS( ($dd2)->cmp, 1 ); ########################################## BEGIN_PGML_SOLUTION END_PGML_SOLUTION ENDDOCUMENT(); In reply to tim Payer ### Re: Reducing coefficients of "1" and "0" in the problem display by Davide Cervone - I thought that to achieve this we needed to place the expression within these square brackets such as this: [:: expression :: ]** You are correct, [:: 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 $fp0 is 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. In reply to tim Payer ### Re: Reducing coefficients of "1" and "0" in the problem display by Davide Cervone - As an aside, there are several other issues with your problem. First, when you do $va = Formula("(-$d)"); ## Vertical asymptote$sa = Formula("($a)"); ## Horizontal Asymptote  you 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 Asymptote  or just $va = Real(-$d); ## Vertical asymptote$sa = Real(\$a); ## Horizontal Asymptote

for 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.