## WeBWorK Problems

### cosmetics might matter: solutions & MathObjects

by Dick Lane -
Number of replies: 4
This is a Request For Comment [and suggestions] because I do not believe there is a unique Solution.

I have been revising a variety of my problems to rely on MathObjects. Updating a problem statement & answer has been fairly straight-forward, but revising a solution has taken more effort because fragments of expressions can be important in that context.

A problem I have used as part of assessing whether a student in a Precalculus class is ready-to-go asks:
Solve $a x +$b ($c + x) =$d (x + $e) If a=6 and b=-5, then my old version used FEQ to display the equation as 6 x - 5 (c + x) = d (x + e) [with explicit values for c,d,e]. Also using FEQ, intermediate steps of a solution replaced "(6 + (-5)) x" with "(6 - 5) x" and "1 x" with "x". An example is attached in a .ZIP (with 3 files): equation01.pg equation01-screenshot.png PGcourse.pl ## loads & enables ProblemRandomize.pl The screenshot of my updated version shows "6 x + (-5) ($c + x)" instead of "6 x - 5 ($c + x)" and "(6 + (-5)) x" instead of "(6 - 5) x", etc. Replacing current definition of$LHSa in equation01.pg
$abFEQ = FEQ( "$a + $b" ) ;$LHSa = Formula( "($abFEQ)*x +$b*$c" ) ; would display "(6 -5) x" instead of "(6 + (-5)) x". For an elementary algebra course, I would want the finer control to select which of several equivalent expressions was presented during a solution. FWIW: I am content with detail in display of Correct. Bottom Line: Although I will welcome suggestions, I suspect crafting a correct solution and tailoring to a particular audience will require cosmetic controls beyond what MathObjects supplies (or should supply). In reply to Dick Lane ### Re: cosmetics might matter: solutions & MathObjects by Alex Jordan - Hi Dick, MathObject Formulas have a method "reduce" that helps. For example, if$a = 2 and $b = -3, then Formula("$a+$bx") will be 2+(-3)x, but Formula("$a+$bx")->reduce will be 2-3x. The reductions that get applied are here: http://webwork.maa.org/wiki/List_of_parser_reduction_rules_for_MathObject_Formulas (And sometimes it's useful to turn some of them off, as the top of that pge explains how to do.) In reply to Alex Jordan ### Re: cosmetics might matter: solutions & MathObjects by Dick Lane - Thanks, Alex, for your reference to the wiki page with a List of Parser Reduction Rules. My example includes Context() -> flags -> set(reduceConstants => 0) ;$LHS = Formula( "$a * x +$b * ($c + x)" ) ;$RHS = Formula( "$d * (x +$e)" ) -> reduce ;
and adding "-> reduce" to $LHS does not fix an issue involving scope of that reduction. E.g., if a=-5, b=-4, c=-6, that reduced$LHS would display as -(5x + 4(x-6)) rather than -5x - 4(-6 + x).  [There are pedagogical reasons why I want students to confront the latter form.]  An alternative definition of $LHSa shows one way to manage the pieces (sometimes):$abFeq = FEQ( "$a +$b" ) ;
$LHSa = Formula( "($abFeq)*x + $b*$c" ) ;

### Re: cosmetics might matter: solutions & MathObjects

by Alex Jordan -
Absolutely. I completely agree with the pedagogy, and that's why I almost always turn off one or two of the reductions.

This line:

Context()->reduction->set('(-x)-y'=>0);

will stop -x - y from being reformatted as -(x + y). And the ->reduce method will (probably) still do everything you would like it to do.

I also usually like to turn off '(-x)+y', which reorders -x + y into y - x.
FWIW, the example posted with my query was generalized from a problem with a known relation between $a$ and \$b (which was exploited during a subsequent solution).  My immediate question involves ways to adapt that as the problem task is generalized.