## `log` -- the logarithm to an arbitrary base

#### Introduction

`log``(b, x)` represents the logarithm of x to the base b.

#### Call(s)

`log(b, x)`

#### Parameters

`b` | - | either an identifier of domain type `DOM_IDENT` or a real numerical value of type `Type::Positive`.
`x` | - | an arithmetical expression

#### Returns

an arithmetical expression.

### Overloadable:

`x`

#### Side Effects

When called with a floating point argument, the function is sensitive to the environment variable `DIGITS` which determines the numerical working precision.

#### Related Functions

`dilog`, `ln`, `polylog`

#### Details

- Mathematically, log(b, x) coincides with ln(x)/ln(b). Cf. example 3. The logarithm is defined for all complex arguments x <> 0.
- The base b must be real, positive and not equal to 1. Internal simplifications are based on these assumptions.
- For most exact arguments an unevaluated function call is returned subject to some simplifications:
  - If b = exp(1), then log(b, x) = ln(x) is returned.
  - Mathematically, log(b, b^y) = y holds true for any real y. This simplification is implemented for the following cases: i) b is a symbolic identifier and y is of type `Type::Real`, ii) b is numerical and y is integer or rational.
  - Negative integer and rational arguments x are rewritten according to log(b, x) = I*PI/ln(b) + log(b, -x). Rational arguments of the form x = 1/n with some integer n are rewritten according to log(b, 1/n) = -log(b, n).
  - The following special values are implemented:

        log(b, 1) = 0, log(b, -1) = I*PI/ln(b), log(b, +/- I) = +/- I*PI/2/ln(b).

- Floating point results are computed if both arguments are numerical and at least one of them is a floating point number. The imaginary part of the result takes values in the interval (-PI/ln(b),PI/ln(b)] for b>1 (in the interval [PI/ln(b),-PI/ln(b)) for b<1, respectively). The negative real axis is a branch cut, the imaginary part of the result jumps when crossing the cut. On the negative real axis, the imaginary part is PI/ln(b) according to log(b, x) = I*PI/ln(b) + log(b, -x), x < 0. Cf. example 2.
- Note that arithmetical rules such as log(b, x*y) = log(b, x) + log(b, y) are not valid throughout the complex plane. Use properties to mark identifiers as real and apply functions such as `expand` or `simplify` to manipulate expressions involving `log`. Cf. example 5.

#### Example 1

We demonstrate some calls with exact and symbolic input data:

    >> log(b, 2), log(2, 3), log(10, 10^2), log(10, 2*10^2),
       log(2, I), log(b, x^2)

                                                   1/2 I PI          2
            log(b, 2), log(2, 3), 2, log(10, 200), --------, log(b, x )
                                                    ln(2)

Note that the base may be a symbolic identifier. However, expressions are not accepted:

    >> log(b + 1, 2)

          Error: base must be an identifier or of Type::Positive [log]

    >> log(PI^2, 2)

          Error: base must be an identifier or of Type::Positive [log]

Floating point values are computed for floating point arguments:

    >> log(2, 123.4), log(2.0, 5.6 + 7.8*I), log(10.0, 2/10^20)

                6.947198584, 3.263347423 + 1.367856012 I, -19.69897

Some special symbolic simplifications are implemented:

    >> log(b, 1), log(b, -1), log(2/3, (4/9)^10), log(b, b^(-5))

                                    I PI
                                 0, -----, 20, -5
                                    ln(b)

#### Example 2

The negative real axis is a branch cut. The imaginary part of the values returned by `log` jump when crossing this cut:

    >> log(10, -2.0),
       log(10, -2.0 + I/10^1000),
       log(10, -2.0 - I/10^1000)

          0.3010299957 + 1.364376354 I, 0.3010299957 + 1.364376354 I,

             0.3010299957 - 1.364376354 I

#### Example 3

Use `rewrite` to rewrite `log` in terms of `ln`:

    >> rewrite(log(b, x), ln), rewrite(log(10, 200), ln)

                                  ln(x)  ln(200)
                                  -----, -------
                                  ln(b)  ln(10)

#### Example 4

The functions `diff`, `float`, `limit`, `series` etc. handle expressions involving `log`:

    >> diff(log(b, x^2), x), float(log(10, PI + I))

                          2
                       -------, 0.5181068691 + 0.133836127 I
                       x ln(b)

    >> limit(log(10, x)/x, x = infinity),
       series(x*log(x, sin(x)), x = 0)

                                  3          5
                                 x          x           6
                        0, x - ------- - --------- + O(x )
                               6 ln(x)   180 ln(x)

#### Example 5

The functions `expand` and `simplify` react to properties set via `assume`. The following call does not produce an expanded result, because the arithmetical rule log(b, x*y) = log(b, x) + log(b, y) does not hold for arbitrary complex x,y. Note, however, that `expand` rewrites `log` in terms of `ln`:

    >> expand(log(10, x*y))

                                      ln(x y)
                                      -------
                                      ln(10)

However, the rule is valid, if one of the factors is real and positive:

    >> assume(x > 0): expand(log(b, x*y))

                                   ln(x)   ln(y)
                                   ----- + -----
                                   ln(b)   ln(b)

    >> simplify(log(b, x^3*y) - log(b, x) - log(b, y))

                                    2 log(b, x)

    >> unassume(x):

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000