Is integration and differentiation code sepparate?



On 11/12/2010 6:53 AM, Dr. David Kirkby wrote:
> I've been trying to automatically develop a large number of tests for 
> Sage. Hopefully millions of them.
I see no reason why you could not develop an infinite sequence of tests, 
without even going
beyond arithmetic on integers.
>
> Some of those tests actually test Maxima. I've only just started this, 
> but the approach I've taken to date is:
>
> 1) Generate a "random" polynomial using a pseudo random number generator.
> 2) Simplify the polynomail, so the output is in a form that's 
> reproducible.
> 3) Integrate the polynomial.
> 4) Differentiate the result from (3)
> 5) Simplify the result from (4)
> 6) Compare the results from (2) and (5).
>
> All being well, steps (2) and (5) should be equal.
>
> For simple polynomails, this does indeed seem to be the case. I've 
> generated many thousands of them, sometimes with complex coefficients 
> and complex powers, and all seems to be ok.

While I suppose you could find a "bug", it seems to me more likely that 
"random" polynomials are unlike to break anything.
You might try coefficients or exponents that exceed some limit, e.g. 
exceed the integer or floating point ranges of the
underlying representation.  Testing by random input is often unproductive.
>
> I'm just wondering if there's any common code, which might actually 
> mean the such tests are meaningless.
Depending on how you are doing the computation (e.g. on rat forms or 
not), there may be more or less common code.
But having SOME common code, e.g. the display, does not make the tests 
meaningless.  The tests are not
meaningless, just, in this case, probably pointless.  Note that a 
program for differentiation and integration of
polynomials can be written (in Lisp) in about 10 lines of code, and 
although the programs in Maxima are
way longer, you are probably exercising only a very tiny percentage of 
the code.
>
>
>
> I've found more complex cases (using sin, sinh, tan arctan etc) where 
> the results of integrating a function, then differentiating it do NOT 
> lead to back to the original function using Maxima.
Yes, this is a problem in simplification.  You can try evaluating at 
random points, as some people have done.
This too is problematical.

Also, even if a function has the right derivative, that does not mean it 
is the right answer. It might have gratuitous singularities.
(Think of it this way: you can add to the integration answer any 
function whose derivative is zero, and the "check" will not
detect it.  e.g. a step function.)
>
> But I've tried the same equations in Mathematica too, and that also 
> has problems, with the result appearing to be much more complicated 
> than what I started with. Perhaps I'm just expecting too much. Perhaps 
> this approach is not mathematically valid - I'm not a mathematician.

The approach is "mathematically" valid,  and it could be used to (say) 
check the results of tables of indefinite integrals. Sometimes.
It is computationally infeasible for most of the published tables where 
the interesting results cannot be simplified.

Finding bugs in Sage seems to be quite easy, and needs no help. Just 
look on the list of bugs that have already been found.
RJF