Hi everyone. I have found a bug in how Sage computes integrals, but it 
seems to be the case that it can come up in a broad set of situations. This 
bug caused me tremendous embarrassment while teaching Calculus II last 
semester. 

Consider the integral of sqrt( cot(x)^2 ). I think we can all agree that

sqrt( cot(x)^2 ) = abs( cot (x) ) =/= cot(x)

However, I think the interface between Sage and Maxima is causing the 
(incorrect) substitution of sqrt( cot(x)^2 ) = cot(x).

Please click the following:

http://sagecell.sagemath.org/?z=eJwrKMrMK1EA4tT0osQcDYXiwqISDYXk_BKNCs04IwVNHYUKHYWCTH0THQVjLRCtoMnLxctVANaWV5qbWpSZnJgTj88AXLr9NBRy8jSMNAmZmJhUDDMQn3HYtEJ0oesBAEw0SMA=&lang=sage

As you can see there, 

print integral( sqrt( cot(x)^2 ), x, pi/4, 3*pi/4 )

produces an answer of zero. My pencil produces an answer of ln(2), after a 
bit of work.

Numerical methods give us some confirmation. The output of the 
numerical_integral command is an ordered pair. The first number is the 
answer, and the second number is the uncertainty. The command

print numerical_integral( sqrt( cot(x)^2 ), pi/4, 3*pi/4 )

gives an answer which is very close to N(ln(2)), which I believe is 
correct. Next, using the correct substitution sqrt( cot(x)^2 ) = abs( 
cot(x) ) manually, we ask

print numerical_integral( abs( cot(x) ), pi/4, 3*pi/4 )

and get again an answer which is very close to N(ln(2)). However, if we use 
the (incorrect) substitution sqrt( cot(x)^2 ) = cot(x) and then type

print numerical_integral( cot(x), pi/4, 3*pi/4 )

the result is zero, matching the symbolic integral command's incorrect 
answer.

Interestingly, while I do not know Maxima, a colleague of mine does, and he 
says that Maxima will not make this illegal substitution. I'm not in a 
position to verify this claim, but that's what makes me imagine that it 
might be the case that the interface between Sage and Maxima is where the 
bug happens to reside.

The reason I say "extremely broad" is that there are lots of applications 
where one takes the integral of a square root of either a square or a sum 
of squares. These come up via the distance formula. I was hoping to make a 
collection of "labs" or "mini-projects" for the integral calculus and 
multivariable calculus focused on engineering applications. The above bug 
came up in a problem about something relatively mundane... arc length of 
some parametric function. See below.

http://sagecell.sagemath.org/?z=eJwrSyzSUCpR0uTl4uVK0yjRVLBVKC4sKtFQ0NAtzswDCWgrJBcnAxmacUYgdn4xkA1kgnUUFGXmlSgAcWp6UWKOhgLIBB2FEh2Fgkx9Ex0FYy0Qjaw0rzQ3tSgzOTEnHl0Tqg4AHaEp4g==&lang=sage

It would be extremely useful if the bug could be fixed before the start of 
the Fall semester, because I'm teaching the same course again. :-P

After the bug is fixed, I would propose that we create a bunch of doctests 
that ask integral to compute some definite integrals, where those same 
integrals are also computed numerically by numerical_integral. The symbolic 
answer to the definite integral as computed by integral should be tested to 
see if it lies inside of the interval given as output by the 
numerical_integral command. (Perhaps we can double the size of the 
uncertainty to prevent any false alarms.)

Thoughts?
---Greg

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to