WeBWorK Main Forum

Strange Problem Behavior

Strange Problem Behavior

by Jason Aubrey -
Number of replies: 2
Hi All,

I wrote a problem which has the following glitch: In "images" mode, a particular line reads as follows when viewed on the web.

(e.g. if the answer is 9.123 \% enter 9.123 )

The line reads as it should "...enter 9.123" in other display modes. The relevant part of the problem code is simply:

(e.g. if the answer is \(9.123 $PERCENT\) enter \(9.123\) )

The problem goes away if I remove the \( \)-delimiters. Even stranger, the number $4,260 is from the very first seed I used to view the problem, but has persisted even when I changed the problem seed. (The complete code for the problem is below.)

One more point: I've seen the $4,260 on two different computers. Another person looked at it and got similar behavior, but showing a different dollar amount -but when I view the problem as him, it shows 4,260.

Our installation is exhibiting another behavior which may be related: When I add a new blank problem to a set and edit it, the code in the "blank problem" is not the blank problem template code, but the code of the last problem I edited, with the code as it was when I last viewed the rendered problem, even if I did not save it in that state. So, for example, I took off the tex delimiters in the problem above to see if that fixed the problem, but I did not save that change. Even so, when I go to view the source of that problem now, it shows me the version without the delimiters, rather than the saved version with the delimiters (which it is using to actually generate the problem.)

Any ideas about what might be causing this?

Thanks,
Jason

Offending problem code:

##DESCRIPTION
## Simple Interest
##ENDDESCRIPTION

##KEYWORDS('financial mathematics', 'interest', 'simple')

## DBsubject('Financial Mathematics')
## DBchapter('Introduction to Interest')
## DBsection('Simple Interest')
## Date('')
## Author('Jason Aubrey')
## Institution('University of Missouri - Columbia')
## TitleText1('Finite Mathematics')
## EditionText1('11')
## AuthorText1('Barnett, Ziegler, Byleen')
## Section1('3.1')
## Problem1('51')

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

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"contextCurrency.pl", #see webwork.maa.org/doc/cvs/pg_CURRENT/macros/contextCurrency.pl
"answerHints.pl", # To give hints --rac
#"source.pl", # allows code to be displayed on certain sites.
#"PGcourse.pl", # Customization file for the course
);

# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

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

##############################################################
#
# Setup
#
#
Context("Numeric");

$index = random(0,4,1);
@days = (90, 120, 180, 240);
$days = @days[$index];
$days_2 = (1/3)*$days;
$t = $days - $days_2;

$rate = random(5,15, 1);

$orig_p = random(4000,6000,250);
$amt = $orig_p*(1 + ($rate/100)*($days/360));

$new_p = $orig_p + random(.1,.9,.1)*$orig_p*($rate/100)*($days_2/360); #inc by a fraction of interest earned over days_2

$new_rate = ($amt / $new_p - 1) * 360 / $t;


$answer = Real(spf($new_rate*100,"%.3f"));

Context()->flags->set(tolerance=>.0005,tolType=>"absolute");
ANS($answer->cmp->withPostFilter(AnswerHints(
sub {
my ($correct,$student,$ans) = @_;
return (abs($correct-$student)>=.001 && abs($correct-$student)<=.1);
} => ["Close, but your answer must be correct to three decimal places to be counted as correct.", score => 0, replaceMessage => 1]
)));

Context("Currency");
Context()->flags->set(trimTrailingZeros=>1);

$orig_p = Currency($orig_p);
$new_p = Currency($new_p);
$amt = Currency($amt);

##############################################################
#
# Text
#
#

Context()->texStrings;
BEGIN_TEXT
For services rendered, an attorney accepts a \($days\) day note for \($orig_p \) at \( $rate $PERCENT\) simple interest from a client. (Both interest and principal will be repaid at the end of \($days\) days.) Wishing to be able to use her money sooner, the attorney sells the note to a third party for \($new_p\) after \($days_2\) days. What annual interest rate will the third party receive for the investment? (Enter your answer as a percentage correct to three decimal places.)
$PAR
Annual simple interest rate for third party: \{ ans_rule(6) \}\($PERCENT\)
$BR
Note: Be sure that your answer is correct to three decimal places, and that it is expressed as a percentage (e.g. if the answer is \(9.123 $PERCENT\) enter \(9.123\) ) into the answer box.
END_TEXT

##############################################################
#
# Answers
#
#



SOLUTION(EV3(<<'END_SOLUTION'));
$PAR SOLUTION $PAR
Step 1: Compute the amount that will be paid at the end of \($days \) days to the holder of the note:

\[ A = P(1 + rt)\]
\[= $orig_p \left [ 1 + \left ( \frac{$rate}{100}\right ) \left ( \frac{$days}{360}\right ) \right ] \]
\[= $amt \]

Step 2: For the third party, we find the annual rate of interest \(r\) required to make \( $new_p \) grow to \( $amt \) in \( $t \) days; that is, we are to find \( r \) (which is to be converted to \(100r $PERCENT\) ), given \( A = $amt \), \( P = $new_p \) and \( t = \frac{$t}{360} \),
\[ A = P(1 + rt) \]
\[ $amt = $new_p \left[ 1 + r\left ( \frac{$t}{360} \right ) \right ] \]
Solving, we obtain \( r = $answer $PERCENT\).

END_SOLUTION
Context()->normalStrings;


ENDDOCUMENT();


In reply to Jason Aubrey

Re: Strange Problem Behavior

by Jason Aubrey -
Oh, when my message posted to the forum, it changed what I copied from the webpage: The strange line reads:

(e.g. if the answer is 9.123% then enter $4,260)

-In my previous message I copied this from the webpage and the image of "$4,260" somehow got translated to its intended text "9.123"). So, again, the original point was that an image displaying "$4,260" appears in images mode, but in all other display modes "9.123" shows up.

Jason
In reply to Jason Aubrey

Re: Strange Problem Behavior

by Arnold Pizer -
Hi Jason,

The images are stored using the md5 encoding of their TeX string. It is possible but with a very small probability for two different TeX strings to have the same md5 encoding. Originally when we did this WeBWorK checked to see if this occurred and handled things correctly if it did but I don't think we ever saw a case of it happening and I don't think this check is still in the code (I think John Jones at ASU put it in).

So try this. First save the offending image somewhere with its md5 name. Then remove all cached images and try viewing the problem again for the same person. See if you get the correct image. Then check the md5 name. You may have an example of two different short TeX strings having the same md5 encoding.

Arnie