The antiderivative returned by giac (and by maple) for floor(x)^2 is only 
piecewise continuous and this is expected. But both CAS implement 
additional code to check for non continuous antiderivative (in simple 
situations for giac), and they correctly evaluate 
integrate(floor(x)^2,x,0,3/2) to 1/2. For definite integration without 
parameters, giac also checks that the exact answer matches a numeric value 
using approximate algorithms.

On Saturday, January 21, 2023 at 2:14:06 PM UTC+1 oscar.j....@gmail.com 
wrote:

> On Sat, 21 Jan 2023 at 06:43, Jonathan Thornburg <jthor...@gmail.com> 
> wrote:
> >
> > On Fri, Jan 20, 2023 at 07:16:14PM +0200, Georgi Guninski wrote:
> > > I have theoretical reasons to doubt the correctness
> > > of integrals involving `floor`.
> > >
> > > The smallest testcases:
> > >
> > > sage: integrate(floor(x)^2,x)
> > > // Giac share root-directory:/usr/share/giac/
> > > // Giac share root-directory:/usr/share/giac/
> > > Added 0 synonyms
> > > x*floor(x)^2
> > >
> > > sage: integrate(2**floor(x),x)
> > > 2^floor(x)*x
> > >
> > > Would someone check with another CAS or prove/disprove by hand?
> >
> > Maple reports the same result for your first testcase:
> >
> > tux% maple
> > |\^/| Maple 2022 (X86 64 LINUX)
> > ._|\| |/|_. Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 
> 2022
> > \ MAPLE / All rights reserved. Maple is a trademark of
> > <____ ____> Waterloo Maple Inc.
> > | Type ? for help.
> > > int(floor(x)^2, x);
> > 2
> > floor(x) x
> >
> > But, I think Maple and Sage/Giac are both wrong: consider the *definite*
> > integral (latex notation) $I = \int_0^{3/2} \lfloor x \rfloor^2 \, dx$:
> >
> > Then the Sage/Giac indefinite integral implies that
> > $I = \left. x \lfloor x \rfloor^2 \right|^{3/2}_0
> > = (3/2) \lfloor (3/2) \rfloor^2 - 0 \lfloor 0 \rfloor^2
> > = 3/2$
> >
> > But it seems to me that the correct result should be
> > $I = \int_0^{3/2} \lfloor x \rfloor^2 \, dx$
> > = \int_0^1 \lfloor x \rfloor^2 \, dx
> > + \int_1^{3/2} \lfloor x \rfloor^2 \, dx
> > = \int_0^1 0 \, dx + \int_1^{3/2} 1 \, dx
> > = 0 + 1/2
> > = 1/2$
>
> The fundamental theorem of calculus requires that the integrand be
> continuous over the interval of integration but in this case the
> integrand is discontinuous at 1 so you cannot apply the theorem over
> [0, 3/2]. The question is: what do you want to give as the indefinite
> integral of a discontinuous function f given that its antiderivative
> does not exist everywhere?
>
> The expression F = floor(x)^2 * x is a valid antiderivative for f =
> floor(x)^2 for all values of x such that f is continuous. At integer
> values of x the function f is discontinuous and no (two-sided)
> antiderivative exists.
>
> It can still be possible to define a function F so that the integral
> of f over [a, b] is equal to F(b) - F(a) but then is it worth doing
> that rather than just returning a locally valid antiderivative that is
> most likely a simpler expression. In this case a function F could be
> something along the lines of (I haven't checked this carefully):
>
> sum(n^2, (n, 1, floor(x)-1)) + floor(x)^2*(x - floor(x))
>
> In context you should consider whether this is actually a better
> expression or not though. Also keep in mind that it won't be possible
> to do this for all discontinuous functions (e.g. 1/x). Any CAS that
> promises to return indefinite integrals or antiderivatives of
> potentially discontinuous functions will at least in some cases need
> to return expressions that are only locally valid antiderivatives
> rather than always returning a function F that can be used to compute
> definite integrals blindly without checking continuity of the
> integrand.
>
> Given that you can't compute a suitable F in general, is it better to
> try some of the time or just to state clearly in the documentation
> what the limitations are and return the simplest locally valid
> antiderivative expression?
>
> --
> Oscar
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/63ce068d-fe20-41fb-af1d-3a6ce082024en%40googlegroups.com.

Reply via email to