## Forum archive 2000-2006

### Blake Thornton - Library Bug (+weird behavior) ### Blake Thornton - Library Bug (+weird behavior)

by Arnold Pizer -
Number of replies: 0 Library Bug (+weird behavior) topic started 10/14/2005; 10:43:32 AMlast post 10/14/2005; 12:51:37 PM Blake Thornton - Library Bug (+weird behavior) 10/14/2005; 10:43:32 AM (reads: 368, responses: 2) This problem has been driving me nuts this week as 400 student are trying to do and many of them running into problems. Here's the problem from the library (and it appears that one bug has been fixed from the version we're using, but not all of them). rochesterLibrary/setDiffEQ3Separable/ur_de_3_13.pg Harmless enough problem, basically: Solve y'= ay^k, y(0)=y_0 The solution is (obviously): ((-$k+1)*$a*t+$c)**(-1/($k-1)) The first bug (that looks correct in the current problem library) the limits for the fun_cmp weren't correct, but that has been fixed and looks okay now. BUT WAIT! What if y_0<0 and k is odd, then this solution isn't correct. So, I threw in a simple little code: if ( ( $k/2 ) == int($k/2) ) { $adjust = 1 } else {$adjust = -1; }$answer1 = "$adjust * ((-$k+1)*$a*t+$c)**(-1/($k-1))"; BUT WAIT, what if k is even, then the student can factor a negative out of the exponent, as in my student last night who did this: y = (1/(-35t-1/1024))^(1/5) = -(1/(35t+1/1024))^(1/5) But now the limits are screwed up again (because perl won't accept a negative to a fractional power). So, frustrated late last night, I did this: DOCUMENT();TEXT(beginproblem());$showPartialCorrectAnswers = 1;$a = random(2,9,1) * random(-1,1,2);$k = random(4,6,1);$t0 = 0;$y0 = non_zero_random(-6,6,1);$c = 1/$y0**($k-1) + ($k-1)*$a*$t0;$tmin = int( $c / ( ($k-1) * $a )) ;$lim1 = [ $tmin+2 ,$tmin+3 ];$lim2 = [$tmin-3, $tmin-2 ];if ($a < 0) { $lim =$lim1;} else { $lim =$lim2; }if ( ( $k/2 ) == int($k/2) ) { $kodd = 0;} else {$kodd = 1; }if ( $kodd and ($y0 < 0) ) { $adjust = -1;} else {$adjust = 1; }$answer1 = "$adjust * ((-$k+1)*$a*t+$c)**(-1/($k-1))";$answer2 = "-($adjust) * ( -(-$k+1)*$a*t-($c))**(-1/($k-1))";BEGIN_TEXTSolve the separable differential equation[ frac{dy}{dt} = $a y^{$k} ,]and find the particular solution satisfying the initial condition[ y($t0) =$y0. ]$BR( y(t) = ) { NAMED_ANS_RULE(ans1,40) }.$PARHints and warnings (but this may not apply to your webwork question):$BRRemember to check your work by taking derivatives and plugging in the initial condition.$BRRemember that if you take an even root something, there is generally a +/-.You may or may not have to be careful of this. (For example, how does one solve x^2=4?)$BRFollowing the last hint/warning, your solution will not have a +/- in it---you haveto figure out if you want the + or the -.$PAREND_TEXT$ans1 =$inputs_ref->{ans1};$ans1 = '' unless defined($ans1);$anshash11 = calleval( fun_cmp($answer1, vars => 't',limits=> $lim1 ),$ans1);$anshash12 = calleval( fun_cmp($answer1, vars => 't',limits=> $lim2 ),$ans1);$anshash21 = calleval( fun_cmp($answer2, vars => 't',limits=> $lim1 ),$ans1);$anshash22 = calleval( fun_cmp($answer2, vars => 't',limits=> $lim2 ),$ans1);if ( 1 == $anshash11->{score} ) { NAMED_ANS(ans1, fun_cmp($answer1, vars => 't',limits=> $lim1 ));} elsif ( 1 ==$anshash12->{score} ) { NAMED_ANS(ans1, fun_cmp($answer1, vars => 't',limits=>$lim2 ));} elsif ( 1 == $anshash21->{score} ) { NAMED_ANS(ans1, fun_cmp($answer2, vars => 't',limits=> $lim1 ));} elsif ( 1 ==$anshash22->{score} ) { NAMED_ANS(ans1, fun_cmp($answer2, vars => 't',limits=>$lim2 ));} else { NAMED_ANS(ans1, fun_cmp($answer1, vars => 't',limits=>$lim ));}sub calleval { my ($ans_evaluator,$student_answer) = @_; my $rh_ans_hash = ""; if ( ref($ans_evaluator) eq 'AnswerEvaluator' ) { # new style $rh_ans_hash =$ans_evaluator->evaluate($student_answer); } elsif (ref($ans_evaluator) eq 'CODE' ) { #old style $rh_ans_hash = &$ans_evaluator($student_answer); } else { warn "There is a problem using the answer evaluator"; } return$rh_ans_hash;}ENDDOCUMENT(); Now, in theory, I'm trying everything possible and if it works, the student should be given credit. Now, here's the weird behavior. It seems, if you enter a wrong answer, check answers, then enter the right answer, it will be marked wrong. But then immediately resubmit the same answer and then it will marked correct. Very bizarre. Here's the specifics: use seed 110. Enter and submit/check these answers: 1) ((12t-1/81))^(-1/4) (incorrect, marked incorrect w/ error. Fine)2) (-(12t-1/81))^(-1/4) (correct, marked incorrect w/ error. not ok)3) (-(12t-1/81))^(-1/4) (correct, marked correct) Seems bizarre. This assignment is due today. I think I will probably delete this problem from our local problem library. Blake <| Post or View Comments |> John Jones - Re: Library Bug (+weird behavior) 10/14/2005; 11:11:49 AM (reads: 469, responses: 0) Hi, Are you using the oldAnswerMacros, as opposed to the Parser based version of fun_cmp? The weird behaviour you describe is a bug for the old fun_cmp (entered in the webwork bugzilla). The code above is complicated enough that I am not 100% sure it is the bug I am thinking of, but it sounds the same. It can be triggered in any fun_cmp answer where you first enter an answer where fun_cmp will get an error evaluating the students function. So, in almost any problem with fun_cmp, sqrt(x-10000) will do the trick. Then enter the right answer. The problem is caused by webwork checking if the previous answer is the same as the current answer. Evaluating the previous answer generates an error which is not handled properly, and that causes the right answer to be marked wrong. On the next submission, the "function which won't evaluate" is not seen so everything acts as it should. The parser-based fun_cmp doesn't have this bug because it traps the error and handles it better when it tries to evaluate sqrt(x-10000) on the default interval. John <| Post or View Comments |> Blake Thornton - Re: Library Bug (+weird behavior) 10/14/2005; 12:51:37 PM (reads: 468, responses: 0) John, That sounds like it could be it. Awesome. Thanks! We need to update! Blake <| Post or View Comments |>