Average Error: 39.2 → 0.2
Time: 36.3s
Precision: 64
Internal Precision: 1344
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;\log \left(1 + x\right) \le 2.412141953301321 \cdot 10^{-06}:\\ \;\;\;\;x - \left(\frac{1}{2} - x \cdot \frac{1}{3}\right) \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{1 + x}\right) + \frac{1}{2} \cdot \log \left(1 + x\right)\\ \end{array}\]

Error

Bits error versus x

Target

Original39.2
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.412141953301321e-06

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

    if 2.412141953301321e-06 < (log (+ 1 x))

    1. Initial program 0.1

      \[\log \left(1 + x\right)\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.1

      \[\leadsto \log \color{blue}{\left(\sqrt{1 + x} \cdot \sqrt{1 + x}\right)}\]
    4. Applied log-prod0.1

      \[\leadsto \color{blue}{\log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{1 + x}\right)}\]
    5. Using strategy rm
    6. Applied pow1/20.1

      \[\leadsto \log \left(\sqrt{1 + x}\right) + \log \color{blue}{\left({\left(1 + x\right)}^{\frac{1}{2}}\right)}\]
    7. Applied log-pow0.1

      \[\leadsto \log \left(\sqrt{1 + x}\right) + \color{blue}{\frac{1}{2} \cdot \log \left(1 + x\right)}\]
  3. Recombined 2 regimes into one program.

Runtime

Time bar (total: 36.3s)Debug logProfile

herbie shell --seed '#(1072840222 1305617769 1692503039 1353360431 4178980589 1488672652)' 
(FPCore (x)
  :name "ln(1 + x)"

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

  (log (+ 1 x)))