On Fri, 3 Feb 2023 at 09:31, Emmanuel Charpentier
<
emanuel.c...@gmail.com> wrote:
>
> BTW :
>
> ```
> sage: a, b = var("a, b")
> sage: f(x) = floor(x)^2
> sage: f(x).integrate(x, a, b)
> // Giac share root-directory:/usr/local/sage-9/local/share/giac/
> // Giac share root-directory:/usr/local/sage-9/local/share/giac/
> Added 0 synonyms
> No checks were made for singular points of antiderivative floor(sageVARa)^2*sageVARx for definite integration in [sageVARa,sageVARb]
> -a*floor(a)^2 + b*floor(a)^2
> ```
>
> Even accepting `x*floor(x)^2` as an antiderivative of `floor(x)`, this *definite* integral is wrong, *wrong*, **wrong**. One could expect :
>
> ```
> sage: F(x) = f(x).integrate(x) ; F
> x |--> x*floor(x)^2
> sage: F(b) - F(a)
> -a*floor(a)^2 + b*floor(b)^2
> ```
I guess somewhere it is assumed that indefinite integration can be
used in FTOC without checking for discontinuities. The result is then
valid as a definite integral only if both end points lie within an
interval in which the function is continuous. In this particular case
that might not seem like a very useful guarantee but there are
probably other cases where it means that integrate can return
something useful.
Simple cases like floor(x) can be patched up but it's much harder to
solve this in general. The question then is really what guarantee you
want the integrate function to uphold when there are symbolic
parameters because most of the time the choice will be between
returning something like the above or just not returning anything.
A case that is unambiguously wrong is this definite integral that has
no symbolic parameters:
>>> integrate(atan2(sin(x), cos(x)), x)
1/2*arctan(sin(x)/cos(x))^2
>>> integrate(atan2(sin(x), cos(x)), (x,0,pi))
0
Here the integrand actually is continuous within the interior of the
region of integration and really does have an antiderivative but the
antiderivative expression returned by integrate is not differentiable
at pi/2 even though the integrand is continuous there. In this case
the result from SymPy is better:
>>> integrate(atan2(sin(x), cos(x)), x))
atan2(sin(x), cos(x))**2/2
>>> integrate(atan2(sin(x), cos(x)), (x, 0, pi))
pi**2/2
That antiderivative expression is continuous and differentiable
throughout the *interior* of (-pi, pi) just like integrand itself. You
still have to be careful about the end points though so if the
integral goes to pi then it needs to be known whether the
antiderivative expression is valid when approaching pi from the left
or the right so basically a limit should be computed. An example where
SymPy gets this kind of thing wrong is
(
https://github.com/sympy/sympy/issues/24004):
>>> integrate(sin(x)*atan2(sin(x), cos(x)), (x, -pi, pi))
0
>>> integrate(sin(x)*atan2(sin(x), cos(x)), (x, -pi+0.001, pi)).n()
6.28318373671672
>>> integrate(sin(x)*atan2(sin(x), cos(x)), x)
sin(x) - cos(x)*atan2(sin(x), cos(x))
Here the integrand is nonnegative and continuous although not
differentiable at the end points. The antiderivative expression is
discontinuous though. This happens because even though the integrand
is continuous our symbolic expression for it contains discontinuous
functions. The issue is not with the fundamental theorem of calculus
but rather specifically with the limitations of *symbolic*
differentiation and integration with expressions involving non-smooth
functions.
Sage also gets this example wrong but in a different way:
>>> integrate(sin(x)*atan2(sin(x), cos(x)), (x, -pi, pi))
0
>>> integrate(sin(x)*atan2(sin(x), cos(x)), x)
-2*arctan(-2*sin(x)/((sin(x)^2/(cos(x) + 1)^2 - 1)*(cos(x) + 1)))
/(sin(x)^2/(cos(x) + 1)^2 + 1)
+ 2*sin(x)/((sin(x)^2/(cos(x) + 1)^2 + 1)*(cos(x) + 1))
+ 2*arctan(sin(x)/(cos(x) + 1))
That expression is definitely wrong because its derivative is negative
for half of every 2*pi interval.
It could be possible to patch up SymPy's antiderivative by adding
something like 2*pi*floor((x-pi)/(2*pi)) which would give a valid
antiderivative in a formal sense but then that means using more
discontinuous functions in antiderivative expressions. I am not sure
that it actually is better to try to make indefinite integration
always return complete antiderivatives where discontinuous functions
are involved. The same applies in reverse when thinking about
differentiation: adding in delta functions is probably not helpful.
Rather I think that it just needs to be understood and documented that
there are limits to
symbolic differentiation and (indefinite) integration where
discontinuous functions are involved.
The Maple docs explicitly discuss this giving floor(x) as an example.
It says there that:
> Note that the indefinite integral in Maple is defined up to a piecewise constant
> Hence, the results returned by int may be discontinuous at some points.
> For symbolic definite integration, two options control how discontinuities are handled.
> By default, int checks for discontinuities, and computes the integral as a sum of
> independent definite integrals, each of which involves an integrand which has
> no discontinuities in the interior of the interval of integration
https://www.maplesoft.com/support/help/maple/view.aspx?path=int%2Fdetails
--
Oscar