Average Error: 39.1 → 0.3
Time: 54.0s
Precision: 64
Internal Precision: 1344
\[\log \left(1 + x\right)\]
↓
\[\begin{array}{l}
\mathbf{if}\;\sqrt[3]{{\left(\left(\log \left(1 + {x}^{3}\right) - \log \left({\left(x \cdot x\right)}^{3} + {\left(1 - x\right)}^{3}\right)\right) + \log \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(\left(1 - x\right) \cdot \left(1 - x\right) - \left(x \cdot x\right) \cdot \left(1 - x\right)\right)\right)\right)}^{3}} \le -0.003366078258316278:\\
\;\;\;\;\log \left(1 + x\right)\\
\mathbf{if}\;\sqrt[3]{{\left(\left(\log \left(1 + {x}^{3}\right) - \log \left({\left(x \cdot x\right)}^{3} + {\left(1 - x\right)}^{3}\right)\right) + \log \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(\left(1 - x\right) \cdot \left(1 - x\right) - \left(x \cdot x\right) \cdot \left(1 - x\right)\right)\right)\right)}^{3}} \le 5.434804327505188:\\
\;\;\;\;x - \left(\frac{1}{2} - x \cdot \frac{1}{3}\right) \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}\]
Try it out
Enter valid numbers for all inputs
Target
| Original | 39.1 |
|---|
| Target | 0.2 |
|---|
| Herbie | 0.3 |
|---|
\[\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
- Split input into 2 regimes
if (cbrt (pow (+ (- (log (+ 1 (pow x 3))) (log (+ (pow (* x x) 3) (pow (- 1 x) 3)))) (log (+ (* (* x x) (* x x)) (- (* (- 1 x) (- 1 x)) (* (* x x) (- 1 x)))))) 3)) < -0.003366078258316278 or 5.434804327505188 < (cbrt (pow (+ (- (log (+ 1 (pow x 3))) (log (+ (pow (* x x) 3) (pow (- 1 x) 3)))) (log (+ (* (* x x) (* x x)) (- (* (- 1 x) (- 1 x)) (* (* x x) (- 1 x)))))) 3))
Initial program 0.0
\[\log \left(1 + x\right)\]
if -0.003366078258316278 < (cbrt (pow (+ (- (log (+ 1 (pow x 3))) (log (+ (pow (* x x) 3) (pow (- 1 x) 3)))) (log (+ (* (* x x) (* x x)) (- (* (- 1 x) (- 1 x)) (* (* x x) (- 1 x)))))) 3)) < 5.434804327505188
Initial program 58.8
\[\log \left(1 + x\right)\]
Taylor expanded around 0 0.4
\[\leadsto \color{blue}{\left(\frac{1}{3} \cdot {x}^{3} + x\right) - \frac{1}{2} \cdot {x}^{2}}\]
Applied simplify0.4
\[\leadsto \color{blue}{x - \left(\frac{1}{2} - x \cdot \frac{1}{3}\right) \cdot \left(x \cdot x\right)}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed 2018198
(FPCore (x)
:name "ln(1 + x)"
:herbie-target
(if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1)))
(log (+ 1 x)))