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

Error

Bits error versus x

Target

Original39.3
Target0.3
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 x < 0.0001261019754755696

    1. Initial program 58.9

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

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

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

    if 0.0001261019754755696 < x

    1. Initial program 0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 0.0001261019754755696:\\ \;\;\;\;x - \left(x \cdot x\right) \cdot \left(\frac{1}{2} - \frac{1}{3} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019068 
(FPCore (x)
  :name "ln(1 + x)"

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

  (log (+ 1 x)))