Average Error: 13.6 → 0.4
Time: 55.0s
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\left(\sqrt[3]{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)} \cdot \sqrt[3]{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\right) \cdot \sqrt[3]{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)} \le -5.946392597907632 \cdot 10^{+19}:\\
\;\;\;\;\left(wj - \frac{wj}{1 + wj}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\\
\mathbf{elif}\;\left(\sqrt[3]{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)} \cdot \sqrt[3]{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\right) \cdot \sqrt[3]{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)} \le 3.568793011148332 \cdot 10^{-19}:\\
\;\;\;\;x + wj \cdot wj\\
\mathbf{else}:\\
\;\;\;\;\left(wj - \frac{wj}{1 + wj}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\\
\end{array}\]
Try it out
Enter valid numbers for all inputs
Target
| Original | 13.6 |
|---|
| Target | 13.0 |
|---|
| Herbie | 0.4 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
if (* (* (cbrt (- (+ (pow wj 2) x) (* 2 (* wj x)))) (cbrt (- (+ (pow wj 2) x) (* 2 (* wj x))))) (cbrt (- (+ (pow wj 2) x) (* 2 (* wj x))))) < -5.946392597907632e+19 or 3.568793011148332e-19 < (* (* (cbrt (- (+ (pow wj 2) x) (* 2 (* wj x)))) (cbrt (- (+ (pow wj 2) x) (* 2 (* wj x))))) (cbrt (- (+ (pow wj 2) x) (* 2 (* wj x)))))
Initial program 1.5
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub1.5
\[\leadsto wj - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\]
Applied associate--r-1.5
\[\leadsto \color{blue}{\left(wj - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}}\]
Applied simplify0.4
\[\leadsto \color{blue}{\left(wj - \frac{wj}{1 + wj}\right)} + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]
if -5.946392597907632e+19 < (* (* (cbrt (- (+ (pow wj 2) x) (* 2 (* wj x)))) (cbrt (- (+ (pow wj 2) x) (* 2 (* wj x))))) (cbrt (- (+ (pow wj 2) x) (* 2 (* wj x))))) < 3.568793011148332e-19
Initial program 26.5
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 26.5
\[\leadsto wj - \color{blue}{\left(wj - \left({wj}^{2} + x\right)\right)}\]
Applied simplify0.3
\[\leadsto \color{blue}{x + wj \cdot wj}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed 2018208
(FPCore (wj x)
:name "Jmat.Real.lambertw, newton loop step"
:herbie-target
(- wj (- (/ wj (+ wj 1)) (/ x (+ (exp wj) (* wj (exp wj))))))
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))