WeBWorK Main Forum

What's wrong with this problem?

What's wrong with this problem?

by Louis Zulli -
Number of replies: 6
It seems that the .pg file copied below causes the Library Browser to hang. An apache2 process utilizing 100% cpu is spawned, and seems to persist until I manually kill the process. Once this file is removed from the problem directory being browsed, the remaining problems load properly, and there is no hang.

# DESCRIPTION
# arc length for  (x+a)^3 /12  +  (x+a)^(-1)  on  [L,R] (with a >= 0)
# ENDDESCRIPTION

## DBsubject('Calculus')
## DBchapter('Applications of Integration')
## DBsection('Arc Length')
## KEYWORDS('calculus', 'integrals', 'integration', 'arc length')
## TitleText1('Calculus: Early Transcendentals')
## EditionText1('2')
## AuthorText1('Rogawski')
## Section1('8.1')
## Problem1('3')
## Institution('W.H.Freeman')
## Author('Dick Lane')
## Date('05/19/2011')

DOCUMENT();
loadMacros( "PGstandard.pl" , "MathObjects.pl" ,
"contextFraction.pl" ,
"freemanMacros.pl" ) ;

Context( "Fraction" ) ;
# Context() -> flags -> set(reduceConstants => 0,reduceConstantFunctions => 0);

$a = random(1,7,1) ;
$L = random(0,4,1) ; #### allowing L=0 is ok since a > 0
$R = $L + random(1,3,1) ; #### interval [ L , R ]

$W  = Formula( "x + $a" ) ;
$f  = Formula( "$W^3 / 12 + $W^(-1)" ) -> reduce ;
$fp = $f -> D -> reduce ;

$integrand = Formula( "$W^2 / 4  +  $W^(-2)" ) -> reduce ;
$antideriv = Formula( "$W^3 / 12 - $W^(-1)" ) -> reduce ;

TEXT(beginproblem());
$showPartialCorrectAnswers = 0 ;



Context() -> texStrings ;
BEGIN_TEXT
\{ textbook_ref_exact("Rogawski ET 2e", "8.1", "3") \}$BR
The graph of \(\displaystyle f(x) = $f \)
on the interval \( [$L,$R] \) has
arc length $SPACE \{ ans_rule() \}
END_TEXT

$showHint = 3 ; #### default value is 1
BEGIN_HINT
$HINT
\( 1 + \left( y' \right)^2 \) is a perfect square.
END_HINT
Context() -> normalStrings;

$right = $antideriv -> substitute( x => $R ) -> reduce ;
$left  = $antideriv -> substitute( x => $L ) -> reduce ;
$arc   = Compute( "$right - $left" ) ;

ANS( $arc -> cmp() );


$Fp = "\frac{$W^2}{4} - \frac{1}{$W^2}" ;



Context() -> texStrings;
BEGIN_SOLUTION
$SOLUTION
\( y = $f \) implies \( y^\prime = $Fp \) and
\[\begin{aligned}
1 + (y^\prime)^2
 & =  1  +
      \left( \frac{($W)^4}{16}  -  \frac{1}{2}  +  \frac{1}{($W)^4} \right)\\
 & =  \frac{($W)^4}{16}  +  \frac{1}{2} +  \frac{1}{($W)^4}
   =  \left( \frac{($W)^2}{4}  +  \frac{1}{($W)^2} \right)^2
\end{aligned} \]
Since \(\displaystyle $integrand > 0 \) on \( [$L,$R] \),
the arc length is
\[ \begin{aligned}
s & = \int_{$L}^{$R} \sqrt{ 1 + (y^\prime)^2 } \; dx \\
  & = \int_{$L}^{$R }\left( \frac{($W)^2}{4} + \frac{1}{($W)^2} \right) dx \\
  & = \left( $antideriv \right) \Bigg|_{$L}^{$R}  \\
  & = $right - $left
    = $arc
\end{aligned} \]
END_SOLUTION
Context() -> normalStrings;

ENDDOCUMENT();


In reply to Louis Zulli

Re: What's wrong with this problem?

by D. Brian Walton -
Just a guess, based on an experience I had once using my own routines related to fractions.

You are using a Fraction context. When the problem substitutes specific values of x into the formulas, does the "reduce" make the object attempt to cancel common factors? (I do not know because I have not used the Fraction context very much.) If written inefficiently, this could appear to be an very slow loop that might time out, especially when numbers are raised to high enough powers (which happened to my original implementation).

- Brian

In reply to Louis Zulli

Re: What's wrong with this problem?

by Dick Lane -
In hindsight, I see some (minor) revisions to this problem's programming.

a)  computation of $fp is now superfluous: $Fp is computed for display in solution because ->reduce for quotient-rule object $fp was incomplete

b)  use of negative exponent followed by ->reduce does result in display of stacked fraction in typeset stuff, but it would have been simpler to use
$f  = Formula( "$W^3 / 12 + 1/$W" ) ;
$integrand = Formula( "$W^2 / 4  +  1/$W^2" ) ;
$antideriv = Formula( "$W^3 / 12 - 1/$W" ) ;

c)  a few extra uses of \displaystyle would improve readability


On the other hand, ->substitute was used instead of ->eval for reasons well-documented in our wiki.

On the third hand, using the reduce function (from PGauxiliaryFunctions.pl, loaded via PGstandard.pl) provides an alternative to invoking Fraction context to reduce quotients of integers.

I, too, would like to learn what causes the problem(s) reported by Louis.
In reply to Dick Lane

Re: What's wrong with this problem?

by Louis Zulli -
Thanks for the feedback. Haven't had much time to think, but I can report that the hang disappears if the ->reduce method is omitted from the following:

$f  = Formula( "$W^3 / 12 + $W^(-1)" ) -> reduce ;

$integrand = Formula( "$W^2 / 4  +  $W^(-2)" ) -> reduce ;
$antideriv = Formula( "$W^3 / 12 - $W^(-1)" ) -> reduce ;
In reply to Dick Lane

Re: What's wrong with this problem?

by Louis Zulli -
Actually, the hang seems related to the combination of negative exponents and ->reduce. There's no hang with the following

$f  = Formula( "$W^3 / 12 + 1/$W" )->reduce;
#$fp = $f -> D -> reduce ;

$integrand = Formula( "$W^2 / 4  +  1/$W^2" )->reduce;
$antideriv = Formula( "$W^3 / 12 - 1/$W" )->reduce;
In reply to Louis Zulli

Re: What's wrong with this problem?

by Davide Cervone -
Louis:

I can't seem to reproduce the problem. The problem runs fine for me in the Library Browser. I tried in the developer version as well as version 2.4.9. What version of WeBWorK are you using?

Now, I put the file you quoted above in a separate file in my templates directory, so I wasn't getting it out of the Ragowski directory. Does it work if you do that?

Davide
In reply to Davide Cervone

Re: What's wrong with this problem?

by Louis Zulli -
Hi Davide,

We're still running 2.4.7, so perhaps the issue has been resolved since then.

Yes, the same hang occurs when the .pg file is located in my course's templates directory.

Thanks for investigating.

Louis

PS---We have 2.5.? running on a development server, so I'll try the problem there when I get a chance. But out production server is a bit behind.