# [ADOL-C] Bug in extreme cases of pow()

Kshitij Kulshreshtha kshitij at math.upb.de
Thu Jul 31 05:15:28 EDT 2014

Hello,

for y = pow(x,e) we apply the rule for forward differentiation in your
given direction (\dot{x},\dot{e}). You get:

\dot{y} = e*pow(x,e-1)*\dot{x} + log(x)*pow(x,e)*\dot{e}

Now if you put x = 0, e = 0, you get a NaN from the first, and a -Inf
from the second term. Result is NaN.

If you put x = 0, e = 1, you get NaN from the second term. Total result
is NaN.

Cheers.
Kshitij

As on 2014-07-31 10:43h, Samuel Leweke did write:
> Hi,
>
> I've noticed a bug in some special cases of the pow() function (see the
> code attached).
> The troubling statement is y = pow(x, e). The output for several values
> of x and e (admittedly extreme cases) is given below:
>
> x = 0, e = 0
> y = 1
> dy/dx = nan
> dy/de = nan
> ======================
> x = 1, e = 0
> y = 1
> dy/dx = 0
> dy/de = 0
> ======================
> x = 0, e = 1
> y = 0
> dy/dx = nan
> dy/de = nan
> ======================
> x = 1, e = 1
> y = 1
> dy/dx = 1
> dy/de = 0
>
> Let's check the values produced in each test.
> Test 1: Since 0^0 = 1 and x^0 = 1 for all x != 0, dy / dx should be 0
> here. The value of dy / de is correct because the derivative does not
> exist (0^e is discontinuous at e = 0).
> Test 2: This is correct.
> Test 3: For fixed e, the function x^e is differentiable and its
> derivative dy / dx is 1 for x = 0 and e = 1. For fixed x = 0, we have
> 0^e = 0 for all e > 0. Hence, we should get dy / de = 0 in this case.
> Test 4: This is correct.
>
> Am I doing something seriously wrong or is this really a bug? Is there a
> work around for this bug to get the correct behavior?
>
> Best regards,
> Samuel Leweke
>
>
>
> ------------------------------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------------------------
>
> Forschungszentrum Juelich GmbH
> 52425 Juelich
> Sitz der Gesellschaft: Juelich
> Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
> Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher
> Geschaeftsfuehrung: Prof. Dr.-Ing. Wolfgang Marquardt (Vorsitzender),
> Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
> Prof. Dr. Sebastian M. Schmidt
> ------------------------------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------------------------
>
>
>
>
> _______________________________________________
>

--
Dr. Kshitij Kulshreshtha

Institut für Mathematik,