## PREP 2015 Question Authoring - Archived

by tim Payer -
Number of replies: 9
I have a simple problem regarding a reduction for the correct answer display.

The code below asks the student to take the derivative of a natural log function working on a root. The student's Result is entered in a fully reduced form and is marked correct with green fields, but the "Correct Answer" from which the student is to compare their answer looks quite different and is not reduced.
I have tried using reduce, and changing the context to fractions but resulted in more errors.

Does anyone have a helpful suggestion?

I have attached the out put in a jpeg. and the code of the problem is below.

Thanks, Tim

# Webwork Workshop 2015  for Payer, Homework 1, Practice:
# Exercises to practice derivative of log  reductions.

DOCUMENT();
"MathObjects.pl",
"PGML.pl");
Context("Numeric");
#Context("Fraction");
#Context("Fraction-NoDecimals");
#Context("LimitedFraction");
$a = Real(random(3,8,1));$b =Real(random(2,9,1));
$c =Real(random(2,9,1));$f = Compute(" ln(x^(($b)*(1/$a)))");
$g =$f ->D;
$h =Formula("$g")->reduce;

TEXT(beginproblem());
BEGIN_PGML

###Find the derivative of [f(x) = \ln\left(\root [$a] \of {x^[$b]}\right)] ###

[f'(x) = ] [______________]{$h} END_PGML BEGIN_PGML_SOLUTION *SOLUTION* END_PGML_SOLUTION ENDDOCUMENT(); In reply to tim Payer ### Re: "Correct Answer" reduction by Daniele Arcara - I tried playing around with this, and I do not see how to fix. Even a simple product of powers of x does not get reduced. For example, I tried this:$uno = Formula("x**2");
$due = Formula("x**3");$tre = Compute("$uno*$due")->reduce();

If I then write [$tre], it writes x^3*x^2 instead of writing x^5. In reply to Daniele Arcara ### Re: "Correct Answer" reduction by Davide Cervone - As I mentioned last Monday, MathObjects is not a computer algebra system, and it doesn't do much in the way of simplification. The main purpose of the reduce() method is to get rid of coefficients like 1x, to remove terms like 0x, and to make things like x + (-2) into x-2. The only algebraic changes it makes is to factor our minus signs so that it can cancel them, and it will rewrite -2x+3 as 3-2x. other than that, it leaves your expression alone. The complete list of reductions is available on the Wiki, and you can see that it is not extensive. That is what I mean by "MathObject is not a CAS". If you want to have the derivative formula in a particular form that is not what the D() method produces, you will need to enter that as a Formula() yourself. In reply to Davide Cervone ### Re: "Correct Answer" reduction by tim Payer - Thanks Davide, And yes I do recall you stating during the slide presentation that "MathObject is not a CAS". But could I follow up with another reduction question? I changed the code in the problem to show a completely reduced answer for for the derivative in the Correct answer display. But now my problem is that a students answer does not have to be reduced. Is there a way that I can require students to enter their answers in a reduced form and perhaps prompt them to reduce such an answer? The LimitedFraction Context works great in this regard, but it seems that this context only works with numeric values and not when variables are included in the answer. Please see the code and images below. # Webwork Workshop 2015 for Payer, Homework 1, Practice: # Exercises to practice derivative of log reductions. DOCUMENT(); loadMacros("PGstandard.pl", "MathObjects.pl", "PGML.pl"); Context("Numeric");$a = Real(random(3,8,1));
$b =Real(random(2,9,1));$c =Real(random(2,9,1));
$f = Compute(" ln(x**(($b)(1/$a)))"); ($br,$ar) = reduce($b,$a); #loadMacros("contextFraction.pl"); #Context("Fraction"); #Context("Fraction-NoDecimals"); #Context("LimitedFraction");$g =Formula("($br/($ar x))");

TEXT(beginproblem());
BEGIN_PGML

###Find the derivative of [f(x) = \ln\left(\root [$a] \of {x^{[$b]}}\right)] ###

[f'(x) = ] [______________]{$g} END_PGML BEGIN_PGML_SOLUTION *SOLUTION* END_PGML_SOLUTION ENDDOCUMENT(); In reply to tim Payer ### Re: "Correct Answer" reduction by Davide Cervone - Is there a way that I can require students to enter their answers in a reduced form and perhaps prompt them to reduce such an answer? No, there is no context that enforces that at the moment. WeBWorK's philosophy in general is to allow any equation that is equivalent to the answer, rather than enforcing particular formats for the problems. For example, there is nothing stopping a student from entering x+1-1 for an answer that expects x. We have found that trying to enforce too much structure on the answer is counter productive in general. Would you disallow 5/6x + 2/3x for example? Both fractions are reduced, and the answer is equivalent. Once you allow some computation (as you do in a Formula), it becomes much more difficult to tell students which operations are allow and which are not. For many equations, it is not clear what the "most reduced" form should be, and students get quite frustrated if they have the "right" answer but WeBWorK doesn't accept it because the form is different from what the instructor wants. For example, you have not indicated that the answer has to be an any particular reduced form, so it would come as a surprise if their answer were marked wrong when it is numerically correct. A note about fomat: you are using a heading for your formula, which is a bad idea, in general, since your question is not a heading. This may not seem like much of an issue, but you should not misuse the semantics of the layout that you are creating. For example, students with visual challenges who need screen readers will get the wrong idea from your problem, since they will be informed that your question is a 3rd-level heading, and this will be extra confusing because there is no 1st or 2nd-level headings. If you want bold lettering, use bold, not headings (but I'd still recommend you not use bold either, as there is no need for it to be highlighted). Do not over specify layout. You may think you are making things look nicer, but you are just making things harder for people in the long run. In reply to Davide Cervone ### Re: "Correct Answer" reduction by Valerio De Angelis - On this topic, I am currently using WeBWorK for a developmental math class, where, for example, the skill of reducing a fraction from 8x^3y/(2xy^3) to 4x^2/y^2 is exactly what is tested in a problem, or where the student is asked to derive the expression x^2-2xy+y^2, given the expression (x-y)^2. Years ago we had some custom made macros written for these and similar problems, but I do not have access to those files now. I would be quite interested in learning how to handle problems like that. In reply to Valerio De Angelis ### Re: "Correct Answer" reduction by Davide Cervone - I didn't mean to say that this isn't something that people want to test, only that WeBWorK isn't designed for it, and that in general it is a hard thing to test well. WeBWorK does have a few contexts for certain well-defined situations. One is the LimitedPolynomial context defined contextLimitedPolynomial.pl. It provides a means of requires polynomials in expanded form, so would allow x^2-2xy+y^2 but not (x-y)^2. So that could be used for the second version. For the first, there is a RationalFunction context defined in contextRationalFunction.pl that forces the student answer to be a rational function (a quotient of polynomials), but it doesn't require the quotient to be reduced. You could use this to ensure that the result is a rational function equal to the right answer, and then use a custom checker to take apart the fraction and test the numerator to see if it matches the numerator of the correct answer. That would ensure that it is reduced (provided the correct answer is). This approach could be used for Tim Payer's 9/6x as well, but I would not want to use the RationalFunction context there, as that would give away something about the form of the answer if the student entered certain incorrect answers. But a custom checker that checked if the answer is correct, is a fraction, and has numerator equal to what you expect could be used to check for the reduced fraction. I'll see if I can put tougher an example before class today. In reply to Valerio De Angelis ### Re: "Correct Answer" reduction by Davide Cervone - OK, here is a custom checker that does what I outlined above. DOCUMENT(); loadMacros( "PGstandard.pl" "MathObejcts.pl", "PGML.pl", "contextRationalFunction.pl", "PGcourse.pl", ); Context("RationalFunction"); Context()->variables->are(x=>'Real',y=>'Real');$f = Formula("4x^2/y^2");
$cmp =$f->cmp(checker => sub {
my ($correct,$student,$ans) = @_; return 0 unless$correct == $student; return 0 unless$student->{tree}->class eq "BOP" && $student->{tree}{bop} eq "/"; my$cnum = Formula($correct->{tree}{lop}); my$snum = Formula($student->{tree}{lop}); Value->Error("Your answer isn't reduced") unless$cnum == $snum; return 1; }); BEGIN_PGML [:8x^3/(2xy^2):] reduces to [_____________]{$cmp}
END_PGML

ENDDOCUMENT();


The custom checker tests whether the student and correct answer are equal (and return 0 if not), then checks if they student answer is a fraction (so that we know we can remove its numerator for the next test), and if so, it takes the numerators of both the correct and student answers and makes them in to Formula objects on their own, and compares them. If they are not equal, we produce a message for the student telling her that the answer isn't reduced (we already know it is correct). Otherwise, we return 1 for full credit.

Tim could use essentially the same custom checker for his situation, but in the Numeric context. Note, however, that this would not prevent answers like 3/(1+1)x or 3/(2x-x) in his case, since we are not enforcing polynomial format in the Numeric context.