Is integration and differentiation code sepparate?
Subject: Is integration and differentiation code sepparate?
From: Dr. David Kirkby
Date: Sun, 14 Nov 2010 02:08:52 +0000
On 11/12/10 03:37 PM, Richard Fateman wrote:
> 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.
I would not disagree with that statement.
Neither do I consider that a particularly helpful comment. Why is it Richard,
you *always* have to come up with such useless information?
You are clearly no fool, and while you know I'm not a mathematician, you are
clearly aware I'm I'm not so stupid to be able to work that out myself.
So what is the point in saying it?
Others on the Maxima list have been only helpful in their comments, but you
start off with a really stupid one of course.
>> 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.
You say it is "often" unproductive, so I assume that means it "occasionally" is.
I was intending trying large values too. I have at this point restricted things
to integers.
>> 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.
The polynomials was just a starting point. I've even been told that with complex
powers they are not considered polynomials, so I have learned something there.
> 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.
It sounds from the comments of Karl-Dieter that I'm actually using Maxima for
the integration and Pynac/Ginac for the differentiation, so it seems that
issues of common code probably non-issues.
>> 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
Of course, I was expecting that comment too. You started the message by telling
me something I obviously knew. You then conclude the email by telling me
something else I obviously already knew. Perhaps I should send you an email tell
you that 1+1=2, and concluding by telling you 5x8=40. It would be no more stupid
than your comments.
I would add I have found a few of them by randomised testing. For example, I
found that
sage: seed(1,2)
will cause Sage to crash. 'seed' is supposed to take one argument, but by giving
it two, I can crash Sage.
Dave