autodiff.log

autodiff.log(x, base=2.718281828459045)

Return the logarithm of x of any base, default to natural log.

Parameters
xint, float, Dual
baseint, float
Returns
outfloat or Dual

Notes

The log of x is undefined when x is less than or equal to 0.

Examples

>>> ad.log(2)
0.6931471805599453
>>> x = ad.Dual(2, -1.5)
>>> ad.log(x)
Dual(0.6931471805599453, array([-0.75]))

Logarithm with different base:

>>> x = ad.Dual(2, -1.5)
>>> log(x, base=10)
Dual(0.30102999566398114, array([-0.32572086]))
>>> x = ad.Dual(2, -1.5)
>>> log(x, base=2)
Dual(1.0, array([-1.08202128]))

Derivative undefined:

>>> x = ad.Dual(0, 1)
>>> ad.log(x)
Traceback (most recent call last):
...
ValueError: Log of x is undefined for x = 0

Error when base is non-positive:

>>> x = ad.Dual(1, 1)
>>> ad.log(x, base=0)
Traceback (most recent call last):
...
ValueError: Logarithm base must be positive