WeBWorK Problems

Correct answer marked incorrect with Currency context

Correct answer marked incorrect with Currency context

by Nathan Wodarz -
Number of replies: 9
I gave the following problem on a homework set, and a student with seed 3515 gave the correct answer to part (A), but it was marked incorrect, despite displaying as the correct answer. As far as I can tell, she was the only student to have this problem. Can anyone help with this?

Nathan

TEXT(&beginproblem);
Context("Currency");
$showPartialCorrectAnswers = 1;

@periods = ("annually","semiannually","quarterly","monthly","weekly","daily");
@ms = (1,2,4,12,52,365);

$mm = random(1,4);
$period = $periods[$mm];
$m = $ms[$mm];

$rate = random(5,10);
$r = $rate/100;

$t1 = random(1,6);
$t2 = $t1 + random(1,6);

$p = 5000*random(1,10);
$P = Currency($p);

$a1 = $p*(1+$r/$m)**($m*$t1);
$a2 = $p*(1+$r/$m)**($m*$t2);

$A1 = Currency($a1);
$A2 = Currency($a2);
BEGIN_TEXT;
If $P is invested at $rate$PERCENT compounded $period, what is the amount after
$HR
(A) $t1 years?
$PAR
Answer: \{ans_rule(8)\}
$PAR
(B) $t2 years?
$PAR
Answer: \{ans_rule(8)\}
$PAR
(Use dollar signs for monetary values)
END_TEXT
ANS($A1->cmp);
ANS($A2->cmp);
ENDDOCUMENT();
In reply to Nathan Wodarz

Re: Correct answer marked incorrect with Currency context

by Jason Aubrey -
Hi Nathan,

With this problem and seed, WeBWorK reports that $5352.125 is the correct answer. Your student probably got exactly this and rounded up to $5352.13, which WeBWorK counts as incorrect. The reason for this is that perl (and many (most?) other programming languages use a method for tie-breaking (when a 5 follows the last desired digit) which differs from what students are taught. It's called "round half to even" or "Banker's rounding" or "unbiased rounding". You can read about it here:

http://en.wikipedia.org/wiki/Rounding

I handle this by loosening up the default tolerance in the currency context via

Context()->flags->set(tolerance=>0.01,tolType=>"absolute");

The default is tolerance=>0.005, tolType=>"absolute".

Hope this helps,
Jason
In reply to Nathan Wodarz

Re: Correct answer marked incorrect with Currency context

by Davide Cervone -
Jason is on the right track, but isn't quite right in the details of his response. He is right that the reason that the correct answer isn't accepted is because of the tolerance: $5352.12 is not within .005 of the "correct" answer, which is 5352.125 as he points out. But $5352.13 isn't within .005 either, so neither answer is accepted.

On the other hand, if you change the tolerance to .01 as Jason suggests, however, will allow both $5352.12 and $5352.13 to be marked correct. That may or may not be what you want. In fact setting the tolerance to anything larger than .005 will do that. It is the (rare) case of a number of the form .nn50000... that is the one case where this happens.

A better solution would be to round or truncate your original value to have only two decimals. I have added two methods for the Currency object that accomplish this:

    $m = Currency(5352.125)->truncate;
and
    $m = Currency(5352.125)->round;
These either truncate or round the decimal. It appears from my tests that perl rounds .125 down but I seem to recall doing some tests in the past that suggest that this might not be consistent for other decimal values ending in 5.

Hope that helps.

Davide

In reply to Davide Cervone

Re: Correct answer marked incorrect with Currency context

by Jason Aubrey -
Hi Davide,

Thanks for those updates to the Currency context. They will be useful.

One clarification: A calculator gives $5253.125 for this calculation. We are speculating that the student entered $5253.13 and WeBWorK marks this as incorrect. However, the point I made in my original reply is correct - WeBWorK does accept $5253.12.

More generally, isn't the accepted range for any tolerance of the form [ans-e,ans+e)?

Thanks,
Jason
In reply to Jason Aubrey

Re: Correct answer marked incorrect with Currency context

by Davide Cervone -
Hmm. My tests show neither $5352.12 nor $5352.13 are accepted. I also just checked
    Context("Currency");
    $m = Currency(5352.125);
    TEXT(ans_rule(10));
    ANS($m->cmp)
and neither were marked correct.

As for the tolerance, the interval is open at both ends. This is how the traditional answer checkers worked, and so MathObjects followed that same pattern. I would be willing to make the change if everyone thinks that would be better.

Davide

In reply to Davide Cervone

Re: Correct answer marked incorrect with Currency context

by Jason Aubrey -
Here's what webwork tells me

$5253.12 $5253.12 incorrect
$5798.47 incorrect

Yes, you're right it marks $5253.12 as incorrect, but it's also telling me this is the correct answer (which I believed). Is this what you see when you try this, or am I missing something?

## http://wwrk.maa.org/moodle/mod/forum/discuss.php?d=459
## seed 3515

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

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"contextCurrency.pl",
#"source.pl", # allows code to be displayed on certain sites.
#"PGcourse.pl", # Customization file for the course
);

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;

##############################################################
#
# Setup
#
#

TEXT(&beginproblem);
Context("Currency");
$showPartialCorrectAnswers = 1;

@periods = ("annually","semiannually","quarterly","monthly","weekly","daily");
@ms = (1,2,4,12,52,365);

$mm = random(1,4);
$period = $periods[$mm];
$m = $ms[$mm];

$rate = random(5,10);
$r = $rate/100;

$t1 = random(1,6);
$t2 = $t1 + random(1,6);

$p = 5000*random(1,10);
$P = Currency($p);

$a1 = $p*(1+$r/$m)**($m*$t1);
$a2 = $p*(1+$r/$m)**($m*$t2);

$A1 = Currency($a1);
$A2 = Currency($a2);
BEGIN_TEXT;
If $P is invested at $rate$PERCENT compounded $period, what is the amount after
$HR
(A) $t1 years?
$PAR
Answer: \{ans_rule(8)\}
$PAR
(B) $t2 years?
$PAR
Answer: \{ans_rule(8)\}
$PAR
(Use dollar signs for monetary values)
END_TEXT
ANS($A1->cmp);
ANS($A2->cmp);
ENDDOCUMENT();
In reply to Jason Aubrey

Re: Correct answer marked incorrect with Currency context

by Davide Cervone -
Jason:

Yes, that is what I'm seeing as well. The reason is that the correct answer is shown with two decimals, and so .125 was rounded down to .12. But neither .12 nor .13 is less than .005 from .125, so neither answer is marked correct. I realize that this is inconsistent and undesirable; I was only trying to explain why it occurred. Your suggestion of using a half-open interval would have made one or the other of these be marked correct, which is (in my opinion) a good reason to consider changing to use it.

Mike:

Jason and I were not talking about the interval in the domain (which was where the limits of 0 to 1 occur) but rather the range of acceptable values in the co-domain of the function. That is, if the correct answer is C and the tolerance is t, we mark answers within the interval (C-t,C+t) as correct and others as incorrect. Jason was suggesting (or perhaps assuming) that the interval was [C-t,c+t), which has the disadvantage of being asymmetric, but the advantage of making it easier to handle discrete situations, like the currency context.

Davide
In reply to Davide Cervone

Re: Correct answer marked incorrect with Currency context

by Arnold Pizer -
Hi,

In Currency context, I assume an absolute tolerance of .005 is used. Would it be better to use e.g. .005000001 ? This would allow two correct answers in the above case, but that covers the cases of students rounding up or down. It would allow a wrong answer in some extremely rare cases where the student error in in the 8 or 9 th decimal place but floating point errors might also creep in around there.

Arnie
In reply to Davide Cervone

Re: Correct answer marked incorrect with Currency context

by Michael Gage -
Our principal reason for leaving the answer interval open on both ends was that we set the default interval to (0, 1) and 0 was frequently a bad value to use (e.g. for testing 1/x).

My main argument for continuing the tradition is that it has worked pretty well so far. :-)
In reply to Michael Gage

Re: Correct answer marked incorrect with Currency context

by Nathan Wodarz -
Thanks to everyone for the prompt replies.

This was actually the third time I've used this problem, along with several dozen related exercises, and it's the first time I've ever seen this issue arise. It doesn't really strike me that change is needed.

Nathan