Average Error: 39.1 → 0.2
Time: 1.1m
Precision: 64
Internal Precision: 1408
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;\log \left(1 + x\right) \le 2.574642621485221 \cdot 10^{-08}:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + x\right)\\ \end{array}\]

Error

Bits error versus x

Target

Original39.1
Target0.2
Herbie0.2
\[\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 (log (+ 1 x)) < 2.574642621485221e-08

    1. Initial program 59.2

      \[\log \left(1 + x\right)\]
    2. Taylor expanded around 0 0.2

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

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

    if 2.574642621485221e-08 < (log (+ 1 x))

    1. Initial program 0.3

      \[\log \left(1 + x\right)\]
  3. Recombined 2 regimes into one program.

Runtime

Time bar (total: 1.1m)Debug log

herbie shell --seed '#(991339738 1419949195 2842012120 4157638069 1320221275 2092628673)' 
(FPCore (x)
  :name "ln(1 + x)"

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

  (log (+ 1 x)))