# ExpandedPolynomial1

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

## Polynomial Multiplication (Expanding)

This PG code shows how to require students to expand polynomial multiplication.

• Download file: File:ExpandedPolynomial1.txt (change the file extension from txt to pg when you save it)
• File location in NPL: `NationalProblemLibrary/FortLewis/Authoring/Templates/Algebra/ExpandedPolynomial1.pg`

PG problem file Explanation

Problem tagging:

```DOCUMENT();
"PGstandard.pl",
"MathObjects.pl",
"contextLimitedPolynomial.pl",
"contextPolynomialFactors.pl",
"contextLimitedPowers.pl",
);

TEXT(beginproblem());
```

Initialization: We need all of these macros.

```#
#  Vertex form
#
Context("Numeric");
\$n = list_random(4,6);
\$a = random(2,4,1);
\$b = (\$a+\$n);
\$h = (\$b-\$a)/2;
\$k = \$h**2+\$a*\$b;
\$vertexform = Compute("(x-\$h)^2-\$k");

#
#  Expanded form
#
Context("LimitedPolynomial-Strict");
\$p = \$h**2 - \$k;
\$p = 2*\$h;
\$expandedform = Formula("x^2 - \$p x + \$p")->reduce;

#
#  Factored form
#
Context("PolynomialFactors-Strict");
Context()->flags->set(singleFactors=>0);
LimitedPowers::OnlyIntegers(
minPower => 0, maxPower => 1,
message => "either 0 or 1",
);
\$factoredform = Compute("(x+\$a)(x-\$b)");
```

Setup: To construct this quadratic, we choose a nice factored form `(x+\$a)(x-\$b)` and from it we construct its vertex form (a(x-h)^2+k) and expanded form (ax^2+bx+c).

For the expanded form we use the `LimitedPolynomial-Strict` context, construct the coefficients `\$p` and `\$p` as Perl reals, and then construct `\$expandedform` using these pre-computed coefficients. This is because the LimitedPolynomial-Strict context balks at answers that are not already simplified completely.

For the factored form we need to change to the `PolynomialFactors-Strict` context and restrict the allowed powers to either 0 or 1 using the `LimitedPowers::OnlyIntegers` block of code. Note: restricting all exponents to 0 or 1 means that repeated factors will have to be entered in the form `k(ax+b)(ax+b)` instead of `k(ax+b)^2`. Also, restricting all exponents to 0 or 1 means that the polynomial must factor as a product of linear factors (no irreducible quadratic factors can appear). Of course, we could allow exponents to be 0, 1, or 2, but then students would be allowed to enter reducible quadratic factors. There are no restrictions on the coefficients, i.e., the quadratic could have any nonzero leading coefficient. We set `singleFactors=>0` so that repeated, non-simplified factors do not generate errors.

```Context()->texStrings;
BEGIN_TEXT
The quadratic expression \( \$vertexform \)
is written in vertex form.
\$BR
\$BR
(a) Write the expression in expanded form
\( ax^2 + bx + c \).
\$BR
\{ ans_rule(30) \}
\$BR
\$BR
(b) Write the expression in factored form
\( k(ax+b)(cx+d) \).
\$BR
\{ ans_rule(30)\}
END_TEXT
Context()->normalStrings;
```

Main Text: Everything here is as usual. To help students understand how to format their answers, we give examples `ax^2+bx+c` and `k(ax+b)(cx+d)` of what the answers should look like.

```\$showPartialCorrectAnswers = 1;

ANS( \$expandedform->cmp() );
ANS( \$factoredform->cmp() );

```

Answer Evaluation: Everything is as expected.

```
Context()->texStrings;
BEGIN_SOLUTION
\${PAR}SOLUTION:\${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();
```

Solution: