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

Error

Bits error versus x

Target

Original39.2
Target0.2
Herbie0.6
\[\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)) < 0.0

    1. Initial program 59.5

      \[\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}{\left(x \cdot x\right) \cdot \left(x \cdot \frac{1}{3} + \frac{-1}{2}\right) + x}\]

    if 0.0 < (log (+ 1 x))

    1. Initial program 1.4

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

Runtime

Time bar (total: 47.9s)Debug logProfile

herbie shell --seed '#(1070991898 1055468627 4280279443 640792587 928206309 3646738750)' 
(FPCore (x)
  :name "ln(1 + x)"

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

  (log (+ 1 x)))