-
-
Notifications
You must be signed in to change notification settings - Fork 535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indefinite integration for piecewise functions #4721
Comments
comment:1
I don't agree that this should be the default. First, how is the indefinite integral of piecewise function even well-defined? Assuming it somehow makes sense, the definite integral should be the default and the indefinite one (which should be very well documented) should require options. Also, my vote is that one should require the optional "method=indefinite" as opposed to "definite=True". I think "method" is more of a Sage standard. |
Attachment: piecewise_integration.patch.gz |
comment:2
I made integration the default for consistency with other functions. For example,
When integrating a piecewise function in Maple, the result is the indefinite integral. The only difference between the Maple result and the patched Sage code is that Maple defines the integral outside the bounds of the original piecewise function, which my code does not. |
comment:3
Okay. It makes good sense to usually copy the default, or implement an idea used in Maple's interface design. But in this case, the indefinite integral of a piecewise defined function is not well-defined. I have no idea why Maple implemented it. I'm sure they had some reason. But IMHO Sage should not be implementing methods which so not have a well-defined mathematical meaning as a default. As an option (which is very well-documented), I have no objection because whoever would be using it presumably know what it means. However, I don't know what it means to indefinitely integrate a piecewise defined function and your code does not explain it. It might be useful for some, so could you please revise it a bit? |
comment:4
Interestingly, Mathematica Online Integrator gives an answer too, but chops off the constant in each piece. You still get a valid antiderivative, but it is not useful as an indefinite integral. (Since it is discontinuous, it doesn't have to satisfy the conclusion of the FTC.) I do see the value of keeping to mathematically well-defined results, but there is also value in consistency. integrate(f) returning an antiderivative in some cases and a definite integral in others doesn't feel intuitive to me. In any case, I'll clean this code up so that it can be included. It should be useful for people working with continuous probability distributions, if nothing else. (Actually, there must be some other use for it too, because Mathematica does it and their results would not be useful for probability.) |
comment:5
Hi Paul, design discussions like this should not be done in trac since the number of people actually getting emails from this is minuscule compared to the audience on sage-devel. So please send an email with a summary what is proposed and what has been discussed so far to sage-devel. Also mention the ticket and that there are some more details there. Thanks and keep up the good work. Cheers, Michael |
Attachment: piecewise_integration2.patch.gz |
comment:6
I've made some changes and added a new patch. Changing from needs work to needs review. |
comment:7
Works as advertised. I don't care about any design / structure details of calculus, so I think somebody else should look at it. |
comment:8
Sorry, I didn't see this earlier or I would've reviewed it. This does not seem to work as advertised. There was a long thread in sage-devel which I though settled some design issues. One of them was that the FTC should be true for this indefinite integral. For example, the indef int F of the function f defined on (-4,3)
should have the property that F(3)-F(-4) is the area under the curve.
This is not tested. In my option, this needs to be added to the docstring. However, what the docstring says is "If definite=True is given, returns the definite integral."
means. I would expect it to be 19/6. Don't you assume the function is 0 outside |
comment:9
It works as expected if you specify the variable:
I suppose in functions of one variable it would be more consistent (within Sage) to figure out the variable automatically, though? |
comment:10
Yes. Can you please do that and add the FTC example to the docstring? |
Attachment: piecewise_integration3.patch.gz |
comment:11
I've added a patch with the changes requested. |
comment:12
Can you explain how to apply the patches? The third one does not apply cleanly on top of the second one, in 3.3.alpha1. |
comment:15
The last two patches together (first patch #3 then the "default" patch) apply cleanly to 3.3.alpha2. They also pass sage -t. A few comments:
in the docstring. Is this mixing of x's and y's intended or a typo? If intended, why?
in the docstring of the function itself. Not crutial, but it will help others in the future know which part is whose.
yet you have the definite integral
Could you explain this please? I think maybe you meant to say
If so, could you add this example and comment to the docstring please? If you agree to all this, could you just make a small patch to go on top of the previous 2 so I can just apply it in my clone, run sage -t, and give this a positive review? |
comment:16
Attachment: docstring.patch.gz I've attached |
comment:17
These last three patches apply cleanly to 3.3.alpha2 and sage -t passes. I'm giving this a positive review, finally, Thanks Paul for making the changes. |
comment:18
I am seeing two doctests failure:
and
If someone posts additional patches please also fold the patches together. Cheers, Michael |
Attachment: const_doctest.patch.gz |
comment:19
Attachment: piecewise_all_patches.patch.gz Ok, I've added the patches.
|
comment:20
Two strange things: (1) For some reason, I cannot apply the const patch to 3.3.alpha2. However, the diff looks good to me. (2) I applied the "all" patch. This is what I got (intel macbook running 10.4):
However, I know const.tex fails (see Michael's comment above), so I ran sage -testall and waited for the doctests to finish (which is near the beginning of the process). Sure enough,
So I think sage -testall is not reporting all the failures on my machine for some reason. In any case, I would gives this a positive review if I knew it would pass sage -testall. However, it isn't clear to me if the output of sage -testall after this patch is "positive enough" to make a "positive review" appropriate. Any suggestions Michael? |
comment:21
When I ran I'm not sure why the polynomial ring test failed on yours but not on mine. Maybe I'm not working with the latest version of sage. I can understand the interface tests failing, because I don't have those interfaces enabled (unfortunately, I don't have my Maple CD with me so I can't test it, unless the interface works with a remote server). |
comment:22
If it was a *.tex file then it might have been a doc test failure. Can you please run sage -testall on your machine again? I ran my tests on an old intel macbook, which might have it's own oddities. |
comment:23
This time, a different test failed. Same as last time, when I ran that test by itself it passed.
From the log:
So it was just a timeout, not a bad value. Is there a way to disable or extend timeouts? |
comment:24
(a) You can try sage -t -long (see sage -advanced for the details), but that might not help in this case. (b) Since Michael didn't respond with a suggestion of what I should do in this case, |
comment:25
const_doctest.patch applies cleanly for me. The timeout issue will not go away with -long since this is a pexpect problem. I did not try the patch and I am hesitant to merge it since it changes default behavior. I do remember a discussion about this on sage-devel, so if someone could point me to that and show me that we agreed on this change I am more than happy to merge this patch. Cheers, Michael |
comment:26
The thread was
(or search "Integral of piecewise functions" Dec 6, 2008). I can try to install the patches on my work machine but it will take several days to even |
comment:27
I checked the above thread and I am not seeing any consensus by a majority of Sage people that this change is a good idea. I still think it should go in, but I would like to see
I am sorry to be a pain here, but this is how it is :) Cheers, Michael |
comment:28
Thanks Paul, there seems to be a strong consensus to make this go in (and William signed off on it, too), so this will be in 3.3. Cheers, Michael |
comment:29
Merged const_doctest.patch and piecewise_all_patches.patch in Sage 3.3.rc0. Mike: const_doctest.patch touches one doctest in const.tex. Cheers, Michael |
It would be nice to be able to do indefinite integration of piecewise functions in Sage.
I've created a patch which does this. I have made the default behavior of the integral() function of a piecewise function be to return the indefinite integral, and the definite integral is returned only when definite=True is supplied.
CC: @mwhansen
Component: calculus
Issue created by migration from https://trac.sagemath.org/ticket/4721
The text was updated successfully, but these errors were encountered: