## WeBWorK Problems

### reduction of coefficients

by Zak Zarychta -
Number of replies: 4
How might one multply out the coefficients of a derivative

The script below yields (in TeX)
$$\int 0.333333\cdot 3x^{2}+1.5\cdot 2x =$$

I would like the coefficients of x^2 and x to multplied out

Numeric");
Context()->variables->are(x=>"Real");
Context()->constants->are(C=>"Real");
$ia = Compute("1/3*x**3 + (3/2)*x**2 + C");$iax = Formula("$ia")->D('x')->reduce; Context()->normalStrings; and question preamble like so Context()->texStrings; Context()->flags->set(reduceConstants=>1); BEGIN_TEXT (a) $$\int iax =$$ \{ans_rule(20) \}$PAR
END_TEXT
Context()->normalStrings;

### Re: reduction of coefficients

by D. Brian Walton -
Zak,

I haven't seen any other responses. Honestly, for myself, I haven't tried to get this to be automatic. Instead, I would anticipate the reduced form myself. Or, alternatively, I would create an array holding the coefficients of the polynomials. I have generalized the PolyString function in polynomialMacros.pl so that I can send two arrays for numerator and denominator of coefficients where the fractions are automatically put in reduced form.

Also, I wanted to point out a few tips I've learned from others in the forum.

1) When creating $iax, you can just use$iax = $ia->D()->reduce; 2) You might want to consider using the FormulaUpToConstant object type. See: http://webwork.maa.org/wiki/FormulasToConstants This way the student does not need to guess which constant you were looking for. Best of luck - Brian D. Brian Walton Department of Mathematics and Statistics James Madison University In reply to Zak Zarychta ### Re: reduction of coefficients by Davide Cervone - Unfortunately, the MathObject reduction rules are not complex enough to do what you require. The rules were originally intended to do things like remove coefficients of 1 or terms with coefficients of 0, and make x + -a into x - a. They are not a full computer algebra system. In the case of your derivative, the form of the terms in the original equation is ax^r, and the derivative rules make this a(rx^(r-1)). The reduction rules will combine the r-1 into a single number, but don't have the sophistication to reduce a(bx^c) further. Such rules could be added in the future, but they are not currently available, I'm afraid. It is one of the things on my "to do" list, but that isn't going down very quickly, and I don't know when that will happen. Davide In reply to Davide Cervone ### Re: reduction of coefficients by Arnold Pizer - Hi, This might be a case where instead of using Formula("$ia")->D('x')->reduce
you might just want to differentiate the expression yourself.

Also using math objects there is a way to override the default correct answer a student will see with your own custom version. I have done this in the past but now I can't remember how to do it. Davide, can you give a pointer to that? It is very useful in situations just like this. Also e.g. in the case $ia ="x^x" and a problem author doesn't like the form Formula("$ia")->D('x') gives.

Arnie