Average Error: 41.8 → 0.0
Time: 13.4s
Precision: 64
Internal precision: 128
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le 15.465634390463869:\\ \;\;\;\;x - \left(x \cdot x\right) \cdot \left(\frac{1}{2} - \frac{1}{3} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]

Error

Bits error versus x

Target

Original41.8
Comparison6.9
Herbie0.0
\[ \begin{array}{l} \mathbf{if}\;1 + x = 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \log \left(1 + x\right)}{\left(1 + x\right) - 1}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes.
  2. if x < 15.465634390463869

    1. Initial program 59.6

      \[\log \left(1 + x\right)\]
    2. Applied taylor 0.1

      \[\leadsto \left(x + \frac{1}{3} \cdot {x}^{3}\right) - \frac{1}{2} \cdot {x}^2\]
    3. Taylor expanded around 0 0.1

      \[\leadsto \color{blue}{\left(x + \frac{1}{3} \cdot {x}^{3}\right) - \frac{1}{2} \cdot {x}^2}\]
    4. Applied simplify 0.1

      \[\leadsto \color{blue}{x - \left(x \cdot x\right) \cdot \left(\frac{1}{2} - \frac{1}{3} \cdot x\right)}\]

    if 15.465634390463869 < x

    1. Initial program 0.0

      \[\log \left(1 + x\right)\]
  3. Recombined 2 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 13.4s) Debug log

Please include this information when filing a bug report:

herbie --seed '#(1491065919 971386119 1205467865 3303294350 2934498360 3187041437)'
(FPCore (x)
  :name "ln(1 + x)"

  :target
  (if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1)))

  (log (+ 1 x)))