Integral of log() and exp() failing the derivative check

40 views
Skip to first unread message

Georgi Guninski

unread,
Jan 21, 2023, 9:34:11 AM1/21/23
to sage-...@googlegroups.com
I got an integral, which fails the derivative check.

For real positive x, define
f(x)=2^(x - 1/2*I*log(-e^(-2*I*pi*x))/pi - 1/2)
f(x) is just an obfuscation of 2^floor(x) and
for all positive x, f(x) is integer.
Let g(x) be the indefinite integral of f(x)
and let gder(x)=g'(x).
Assuming correct computations, we should have

gder(x)=g'(x)=f(x) (*)

According to sage, gder is the constant $1$
and (*) fails.

sage session:

===
f=2^(x - 1/2*I*log(-e^(-2*I*pi*x))/pi - 1/2)
g=integrate(f,x);gder=g.derivative(x)
g
#1/2*sqrt(2)*(-1)^(-1/2*I*log(2)/pi)*x
gder
#1/2*sqrt(2)*(-1)^(-1/2*I*log(2)/pi)
CC(gder)
#1.00000000000000
x0=5;CC((f-gder)(x=x0))
#31.0000000000000
===

Some questions:
1. What other CASes say about g(x)?
2. Why the derivative test fails?
3. Besides the jumps at integer, do branches of log()
give instability?

Some comments suggest discontinuous functions
cause integral problems. There are built-in
discontinuous functions like tan() which are
widely used.

4. Why tan() integrals are used without problems (?)
when this fails the derivative check?

Emmanuel Charpentier

unread,
Jan 26, 2023, 7:53:41 AM1/26/23
to sage-devel
Indeed :

```
sage: f(x)=2^(x-1/2*I*log(-e^(-2*I*pi*x))/pi-1/2)
```

The key is probably

```
sage: f(x).diff(x)
0
```

This should include an (infinite) series of terms in `dirac(x-k)` for k in integers...

Logical consequence :

```
sage: f(x).integrate(x)
1/2*sqrt(2)*(-1)^(-1/2*I*log(2)/pi)*x
```

That is, your antiderivative is the product of `x` by aconstant, which turns out to be :

```
sage: f(x).integrate(x)/x
1/2*sqrt(2)*(-1)^(-1/2*I*log(2)/pi)
sage: (f(x).integrate(x)/x).simplify()
1/2*sqrt(2)/(-1)^(1/2*I*log(2)/pi)
sage: (f(x).integrate(x)/x).simplify_full()
1
```

Note that `(2^floor(x)).integrate(x).plot((x,0,7/2))` gives :

tmp_0qt8ouke.png

which is correct. BTW :

```
sage: (2^floor(x)).integrate(x)
2^floor(x)*x
```


HTH,

Oscar Benjamin

unread,
Jan 26, 2023, 9:24:05 AM1/26/23
to sage-...@googlegroups.com
On Sat, 21 Jan 2023 at 14:34, Georgi Guninski <ggun...@gmail.com> wrote:
>
> I got an integral, which fails the derivative check.
>
> For real positive x, define
> f(x)=2^(x - 1/2*I*log(-e^(-2*I*pi*x))/pi - 1/2)
> f(x) is just an obfuscation of 2^floor(x) and
> for all positive x, f(x) is integer.
> Let g(x) be the indefinite integral of f(x)
> and let gder(x)=g'(x).
> Assuming correct computations, we should have
>
> gder(x)=g'(x)=f(x) (*)
>
> According to sage, gder is the constant $1$
> and (*) fails.
>
> Some questions:
> 1. What other CASes say about g(x)?

In this case SymPy gives:

In [34]: f = 2**(x-S(1)/2*I*log(-E**(-2*I*pi*x))/pi-S(1)/2)

In [35]: print(f.integrate(x))
sqrt(2)*2**x*x/(2*2**(I*log(-exp(-2*I*pi*x))/(2*pi)))

In [36]: print(f.integrate(x).diff(x))
sqrt(2)*2**x/(2*2**(I*log(-exp(-2*I*pi*x))/(2*pi)))

In [37]: print(expand(f.integrate(x).diff(x) - f))
0

In [38]: print(f.diff(x))
0

In [39]: print(simplify(f.integrate(x)/f))
x

> 2. Why the derivative test fails?

Antiderivatives are not well defined for functions with jump
discontinuities. A true antiderivative only exists for functions
having the intermediate value property:
https://en.wikipedia.org/wiki/Darboux%27s_theorem_(analysis)

Since a true antiderivative does not exist the question is what can
integrate do or what guarantees should be expected of the result that
it returns?

Generally symbolic antiderivatives of discontinuous functions should
be understood as being only defined up to a piecewise constant
function. Another way to think about this is that when you add a
constant of integration like +C to your antiderivative it should be
+C(x) where C(x) is a function whose derivative is zero almost
everywhere but that might be discontinuous at the same places as the
integrand.

Algorithms for finding antiderivatives rely on differentiation which
should also be understood as being well defined only where a function
actually is differentiable. It is not possible for those algorithms to
guarantee that what is returned is a symbolic expression for an
antiderivative that always matches the integral of a function over
*any* chosen interval [a,b] if the function is not continuous in all
of [a,b].

> 3. Besides the jumps at integer, do branches of log()
> give instability?
>
> Some comments suggest discontinuous functions
> cause integral problems. There are built-in
> discontinuous functions like tan() which are
> widely used.
>
> 4. Why tan() integrals are used without problems (?)
> when this fails the derivative check?

In the case of `tan` you still need to understand any antiderivative
as being limited to intervals of width pi. You could not for example
use the expression of an antiderivative for tan to compute the
integral of tan(x) between 0 and 2*pi.

--
Oscar
Reply all
Reply to author
Forward
0 new messages