Average Error: 13.3 → 0.9
Time: 34.7s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \le 1.5405923546191605 \cdot 10^{-19}:\\ \;\;\;\;\left(\sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj} \cdot \sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj}\right) \cdot \sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj} + x\\ \mathbf{else}:\\ \;\;\;\;wj - \left(wj - \frac{x}{e^{wj}}\right) \cdot \frac{1}{1 + wj}\\ \end{array}\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
\mathbf{if}\;wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \le 1.5405923546191605 \cdot 10^{-19}:\\
\;\;\;\;\left(\sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj} \cdot \sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj}\right) \cdot \sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj} + x\\

\mathbf{else}:\\
\;\;\;\;wj - \left(wj - \frac{x}{e^{wj}}\right) \cdot \frac{1}{1 + wj}\\

\end{array}
double f(double wj, double x) {
        double r33142731 = wj;
        double r33142732 = exp(r33142731);
        double r33142733 = r33142731 * r33142732;
        double r33142734 = x;
        double r33142735 = r33142733 - r33142734;
        double r33142736 = r33142732 + r33142733;
        double r33142737 = r33142735 / r33142736;
        double r33142738 = r33142731 - r33142737;
        return r33142738;
}

double f(double wj, double x) {
        double r33142739 = wj;
        double r33142740 = exp(r33142739);
        double r33142741 = r33142739 * r33142740;
        double r33142742 = x;
        double r33142743 = r33142741 - r33142742;
        double r33142744 = r33142740 + r33142741;
        double r33142745 = r33142743 / r33142744;
        double r33142746 = r33142739 - r33142745;
        double r33142747 = 1.5405923546191605e-19;
        bool r33142748 = r33142746 <= r33142747;
        double r33142749 = -2.0;
        double r33142750 = r33142749 * r33142742;
        double r33142751 = r33142739 + r33142750;
        double r33142752 = r33142751 * r33142739;
        double r33142753 = cbrt(r33142752);
        double r33142754 = r33142753 * r33142753;
        double r33142755 = r33142754 * r33142753;
        double r33142756 = r33142755 + r33142742;
        double r33142757 = r33142742 / r33142740;
        double r33142758 = r33142739 - r33142757;
        double r33142759 = 1.0;
        double r33142760 = r33142759 + r33142739;
        double r33142761 = r33142759 / r33142760;
        double r33142762 = r33142758 * r33142761;
        double r33142763 = r33142739 - r33142762;
        double r33142764 = r33142748 ? r33142756 : r33142763;
        return r33142764;
}

Error

Bits error versus wj

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original13.3
Target12.7
Herbie0.9
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))) < 1.5405923546191605e-19

    1. Initial program 17.8

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Taylor expanded around 0 0.8

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

      \[\leadsto \color{blue}{x + \left(wj + -2 \cdot x\right) \cdot wj}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt1.0

      \[\leadsto x + \color{blue}{\left(\sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj} \cdot \sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj}\right) \cdot \sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj}}\]

    if 1.5405923546191605e-19 < (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))

    1. Initial program 2.6

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied distribute-rgt1-in2.7

      \[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\]
    4. Applied *-un-lft-identity2.7

      \[\leadsto wj - \frac{\color{blue}{1 \cdot \left(wj \cdot e^{wj} - x\right)}}{\left(wj + 1\right) \cdot e^{wj}}\]
    5. Applied times-frac2.6

      \[\leadsto wj - \color{blue}{\frac{1}{wj + 1} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj}}}\]
    6. Simplified0.7

      \[\leadsto wj - \frac{1}{wj + 1} \cdot \color{blue}{\left(wj - \frac{x}{e^{wj}}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \le 1.5405923546191605 \cdot 10^{-19}:\\ \;\;\;\;\left(\sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj} \cdot \sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj}\right) \cdot \sqrt[3]{\left(wj + -2 \cdot x\right) \cdot wj} + x\\ \mathbf{else}:\\ \;\;\;\;wj - \left(wj - \frac{x}{e^{wj}}\right) \cdot \frac{1}{1 + wj}\\ \end{array}\]

Reproduce

herbie shell --seed 2019121 
(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))))))