My full code is as follows (with both versions of my attempt to reduce, highlighted).

DOCUMENT();

loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"contextPolynomialFactors.pl",

"contextLimitedPowers.pl",

"PGML.pl",

);

TEXT(beginproblem());

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

#

# Setup

#

$a = non_zero_random(-5,5,1);

$b = non_zero_random(-5,5,1);

$c = non_zero_random(-5,5,1);

Context("Numeric");

#

# Expanded form

#

# Option 1

#$poly = Compute("$a*$b*x**2+($a*$b*$c+$a)*x+$a*$b")->reduce;

# Option 2

$poly = Compute("$a*$b*x**2+($a*$b*$c+$a)*x+$a*$b");

$poly->reduce("(-x)+y" => 0);

#

# Factored form

#

Context("PolynomialFactors-Strict");

Context()->flags->set(singleFactors=>0);

LimitedPowers::OnlyIntegers(

minPower => 0, maxPower => 1,

message => "either 0 or 1",

);

$factored = Compute("$a*($b*x+1)*(x+$c)")->reduce;

BEGIN_PGML

Write the quadratic expression [` [$poly] `] in factored form [` k(ax+b)(cx+d) `].

[________________________]{$factored}

END_PGML

ENDDOCUMENT();

My pseudorandom variables were producing the polynomial -4x^2+10x-4.

Option 1 tidied up the signs nicely, but reversed the x^2 and x terms in order to avoid a leading negative, giving 10x-4x^2-4.

I wanted to see if I could force reduce to keep the terms in order by descending exponent. The documentation at

http://webwork.maa.org/wiki/Introduction_to_Contexts#Reduction_Rules

and

http://webwork.maa.org/wiki/Reduction_rules_for_MathObject_Formulas#.VY7gxEZTPE0

made me think that Option 2 would work. And in fact it did, in the sense that the terms weren't re-ordered; but the output was (-4)x^2+10x+(-4), so now reduce was failing to get rid of unnecessary parentheses.

So my question is, is it possible to set it up so that the output will actually be -4x^2+10x-4?