Jmat.Real.lambertw, newton loop step

Percentage Accurate: 77.5% → 99.7%
Time: 7.6s
Alternatives: 9
Speedup: 313.0×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := wj \cdot e^{wj}\\ wj - \frac{t_0 - x}{e^{wj} + t_0} \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (let* ((t_0 (* wj (exp wj)))) (- wj (/ (- t_0 x) (+ (exp wj) t_0)))))
double code(double wj, double x) {
	double t_0 = wj * exp(wj);
	return wj - ((t_0 - x) / (exp(wj) + t_0));
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    real(8) :: t_0
    t_0 = wj * exp(wj)
    code = wj - ((t_0 - x) / (exp(wj) + t_0))
end function
public static double code(double wj, double x) {
	double t_0 = wj * Math.exp(wj);
	return wj - ((t_0 - x) / (Math.exp(wj) + t_0));
}
def code(wj, x):
	t_0 = wj * math.exp(wj)
	return wj - ((t_0 - x) / (math.exp(wj) + t_0))
function code(wj, x)
	t_0 = Float64(wj * exp(wj))
	return Float64(wj - Float64(Float64(t_0 - x) / Float64(exp(wj) + t_0)))
end
function tmp = code(wj, x)
	t_0 = wj * exp(wj);
	tmp = wj - ((t_0 - x) / (exp(wj) + t_0));
end
code[wj_, x_] := Block[{t$95$0 = N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision]}, N[(wj - N[(N[(t$95$0 - x), $MachinePrecision] / N[(N[Exp[wj], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := wj \cdot e^{wj}\\
wj - \frac{t_0 - x}{e^{wj} + t_0}
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 77.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := wj \cdot e^{wj}\\ wj - \frac{t_0 - x}{e^{wj} + t_0} \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (let* ((t_0 (* wj (exp wj)))) (- wj (/ (- t_0 x) (+ (exp wj) t_0)))))
double code(double wj, double x) {
	double t_0 = wj * exp(wj);
	return wj - ((t_0 - x) / (exp(wj) + t_0));
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    real(8) :: t_0
    t_0 = wj * exp(wj)
    code = wj - ((t_0 - x) / (exp(wj) + t_0))
end function
public static double code(double wj, double x) {
	double t_0 = wj * Math.exp(wj);
	return wj - ((t_0 - x) / (Math.exp(wj) + t_0));
}
def code(wj, x):
	t_0 = wj * math.exp(wj)
	return wj - ((t_0 - x) / (math.exp(wj) + t_0))
function code(wj, x)
	t_0 = Float64(wj * exp(wj))
	return Float64(wj - Float64(Float64(t_0 - x) / Float64(exp(wj) + t_0)))
end
function tmp = code(wj, x)
	t_0 = wj * exp(wj);
	tmp = wj - ((t_0 - x) / (exp(wj) + t_0));
end
code[wj_, x_] := Block[{t$95$0 = N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision]}, N[(wj - N[(N[(t$95$0 - x), $MachinePrecision] / N[(N[Exp[wj], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := wj \cdot e^{wj}\\
wj - \frac{t_0 - x}{e^{wj} + t_0}
\end{array}
\end{array}

Alternative 1: 99.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{e^{wj}} - wj\\ t_1 := x \cdot -4 + x \cdot 1.5\\ \mathbf{if}\;wj \leq -3.65 \cdot 10^{-6}:\\ \;\;\;\;wj + \frac{t_0}{wj + 1}\\ \mathbf{elif}\;wj \leq 3.8 \cdot 10^{-6}:\\ \;\;\;\;{wj}^{3} \cdot \left(\left(\left(-1 - -2 \cdot t_1\right) - x \cdot -3\right) - x \cdot 0.6666666666666666\right) + \left(\left(1 - t_1\right) \cdot {wj}^{2} + \left(x + -2 \cdot \left(wj \cdot x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{wj + 1}, wj\right)\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (let* ((t_0 (- (/ x (exp wj)) wj)) (t_1 (+ (* x -4.0) (* x 1.5))))
   (if (<= wj -3.65e-6)
     (+ wj (/ t_0 (+ wj 1.0)))
     (if (<= wj 3.8e-6)
       (+
        (*
         (pow wj 3.0)
         (- (- (- -1.0 (* -2.0 t_1)) (* x -3.0)) (* x 0.6666666666666666)))
        (+ (* (- 1.0 t_1) (pow wj 2.0)) (+ x (* -2.0 (* wj x)))))
       (fma t_0 (/ 1.0 (+ wj 1.0)) wj)))))
double code(double wj, double x) {
	double t_0 = (x / exp(wj)) - wj;
	double t_1 = (x * -4.0) + (x * 1.5);
	double tmp;
	if (wj <= -3.65e-6) {
		tmp = wj + (t_0 / (wj + 1.0));
	} else if (wj <= 3.8e-6) {
		tmp = (pow(wj, 3.0) * (((-1.0 - (-2.0 * t_1)) - (x * -3.0)) - (x * 0.6666666666666666))) + (((1.0 - t_1) * pow(wj, 2.0)) + (x + (-2.0 * (wj * x))));
	} else {
		tmp = fma(t_0, (1.0 / (wj + 1.0)), wj);
	}
	return tmp;
}
function code(wj, x)
	t_0 = Float64(Float64(x / exp(wj)) - wj)
	t_1 = Float64(Float64(x * -4.0) + Float64(x * 1.5))
	tmp = 0.0
	if (wj <= -3.65e-6)
		tmp = Float64(wj + Float64(t_0 / Float64(wj + 1.0)));
	elseif (wj <= 3.8e-6)
		tmp = Float64(Float64((wj ^ 3.0) * Float64(Float64(Float64(-1.0 - Float64(-2.0 * t_1)) - Float64(x * -3.0)) - Float64(x * 0.6666666666666666))) + Float64(Float64(Float64(1.0 - t_1) * (wj ^ 2.0)) + Float64(x + Float64(-2.0 * Float64(wj * x)))));
	else
		tmp = fma(t_0, Float64(1.0 / Float64(wj + 1.0)), wj);
	end
	return tmp
end
code[wj_, x_] := Block[{t$95$0 = N[(N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * -4.0), $MachinePrecision] + N[(x * 1.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[wj, -3.65e-6], N[(wj + N[(t$95$0 / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[wj, 3.8e-6], N[(N[(N[Power[wj, 3.0], $MachinePrecision] * N[(N[(N[(-1.0 - N[(-2.0 * t$95$1), $MachinePrecision]), $MachinePrecision] - N[(x * -3.0), $MachinePrecision]), $MachinePrecision] - N[(x * 0.6666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(1.0 - t$95$1), $MachinePrecision] * N[Power[wj, 2.0], $MachinePrecision]), $MachinePrecision] + N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(1.0 / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision] + wj), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{e^{wj}} - wj\\
t_1 := x \cdot -4 + x \cdot 1.5\\
\mathbf{if}\;wj \leq -3.65 \cdot 10^{-6}:\\
\;\;\;\;wj + \frac{t_0}{wj + 1}\\

\mathbf{elif}\;wj \leq 3.8 \cdot 10^{-6}:\\
\;\;\;\;{wj}^{3} \cdot \left(\left(\left(-1 - -2 \cdot t_1\right) - x \cdot -3\right) - x \cdot 0.6666666666666666\right) + \left(\left(1 - t_1\right) \cdot {wj}^{2} + \left(x + -2 \cdot \left(wj \cdot x\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{wj + 1}, wj\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if wj < -3.65000000000000021e-6

    1. Initial program 70.8%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg70.8%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub70.8%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg70.8%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative70.8%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in70.8%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg70.8%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg70.8%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub70.8%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in99.1%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/99.1%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified99.1%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]

    if -3.65000000000000021e-6 < wj < 3.8e-6

    1. Initial program 78.5%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg78.5%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub78.5%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg78.5%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative78.5%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in78.5%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg78.5%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg78.5%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub78.5%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in78.5%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/78.6%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified78.6%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
    4. Taylor expanded in wj around 0 100.0%

      \[\leadsto \color{blue}{-1 \cdot \left(\left(0.6666666666666666 \cdot x + \left(-3 \cdot x + \left(1 + -2 \cdot \left(-4 \cdot x + 1.5 \cdot x\right)\right)\right)\right) \cdot {wj}^{3}\right) + \left(\left(1 - \left(-4 \cdot x + 1.5 \cdot x\right)\right) \cdot {wj}^{2} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)\right)} \]

    if 3.8e-6 < wj

    1. Initial program 39.7%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg39.7%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub39.7%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg39.7%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative39.7%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in39.7%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg39.7%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg39.7%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub39.7%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in39.7%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/39.7%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
    4. Step-by-step derivation
      1. +-commutative99.7%

        \[\leadsto \color{blue}{\frac{\frac{x}{e^{wj}} - wj}{wj + 1} + wj} \]
      2. div-inv99.7%

        \[\leadsto \color{blue}{\left(\frac{x}{e^{wj}} - wj\right) \cdot \frac{1}{wj + 1}} + wj \]
      3. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{e^{wj}} - wj, \frac{1}{wj + 1}, wj\right)} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{e^{wj}} - wj, \frac{1}{wj + 1}, wj\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq -3.65 \cdot 10^{-6}:\\ \;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\ \mathbf{elif}\;wj \leq 3.8 \cdot 10^{-6}:\\ \;\;\;\;{wj}^{3} \cdot \left(\left(\left(-1 - -2 \cdot \left(x \cdot -4 + x \cdot 1.5\right)\right) - x \cdot -3\right) - x \cdot 0.6666666666666666\right) + \left(\left(1 - \left(x \cdot -4 + x \cdot 1.5\right)\right) \cdot {wj}^{2} + \left(x + -2 \cdot \left(wj \cdot x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{e^{wj}} - wj, \frac{1}{wj + 1}, wj\right)\\ \end{array} \]

Alternative 2: 99.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{e^{wj}} - wj\\ \mathbf{if}\;wj \leq -4.5 \cdot 10^{-9}:\\ \;\;\;\;wj + \frac{t_0}{wj + 1}\\ \mathbf{elif}\;wj \leq 7 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, wj \cdot x, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{wj + 1}, wj\right)\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (let* ((t_0 (- (/ x (exp wj)) wj)))
   (if (<= wj -4.5e-9)
     (+ wj (/ t_0 (+ wj 1.0)))
     (if (<= wj 7e-9)
       (fma wj wj (fma -2.0 (* wj x) x))
       (fma t_0 (/ 1.0 (+ wj 1.0)) wj)))))
double code(double wj, double x) {
	double t_0 = (x / exp(wj)) - wj;
	double tmp;
	if (wj <= -4.5e-9) {
		tmp = wj + (t_0 / (wj + 1.0));
	} else if (wj <= 7e-9) {
		tmp = fma(wj, wj, fma(-2.0, (wj * x), x));
	} else {
		tmp = fma(t_0, (1.0 / (wj + 1.0)), wj);
	}
	return tmp;
}
function code(wj, x)
	t_0 = Float64(Float64(x / exp(wj)) - wj)
	tmp = 0.0
	if (wj <= -4.5e-9)
		tmp = Float64(wj + Float64(t_0 / Float64(wj + 1.0)));
	elseif (wj <= 7e-9)
		tmp = fma(wj, wj, fma(-2.0, Float64(wj * x), x));
	else
		tmp = fma(t_0, Float64(1.0 / Float64(wj + 1.0)), wj);
	end
	return tmp
end
code[wj_, x_] := Block[{t$95$0 = N[(N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision]}, If[LessEqual[wj, -4.5e-9], N[(wj + N[(t$95$0 / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[wj, 7e-9], N[(wj * wj + N[(-2.0 * N[(wj * x), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(1.0 / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision] + wj), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{e^{wj}} - wj\\
\mathbf{if}\;wj \leq -4.5 \cdot 10^{-9}:\\
\;\;\;\;wj + \frac{t_0}{wj + 1}\\

\mathbf{elif}\;wj \leq 7 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, wj \cdot x, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{wj + 1}, wj\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if wj < -4.49999999999999976e-9

    1. Initial program 74.4%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg74.4%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub74.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg74.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative74.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in74.4%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg74.4%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg74.4%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub74.4%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in99.2%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/99.2%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified99.2%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]

    if -4.49999999999999976e-9 < wj < 6.9999999999999998e-9

    1. Initial program 78.4%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg78.4%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub78.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg78.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative78.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in78.4%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg78.4%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg78.4%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub78.4%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in78.4%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/78.4%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified78.4%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
    4. Taylor expanded in wj around 0 99.7%

      \[\leadsto \color{blue}{\left(1 - \left(-4 \cdot x + 1.5 \cdot x\right)\right) \cdot {wj}^{2} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)} \]
    5. Taylor expanded in x around 0 99.7%

      \[\leadsto \color{blue}{{wj}^{2}} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
    6. Step-by-step derivation
      1. unpow299.7%

        \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
    7. Simplified99.7%

      \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
    8. Taylor expanded in wj around 0 99.7%

      \[\leadsto \color{blue}{{wj}^{2} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)} \]
    9. Step-by-step derivation
      1. unpow299.7%

        \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
      2. fma-def99.7%

        \[\leadsto wj \cdot wj + \color{blue}{\mathsf{fma}\left(-2, wj \cdot x, x\right)} \]
      3. fma-udef99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, wj \cdot x, x\right)\right)} \]
      4. *-commutative99.7%

        \[\leadsto \mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, \color{blue}{x \cdot wj}, x\right)\right) \]
    10. Simplified99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, x \cdot wj, x\right)\right)} \]

    if 6.9999999999999998e-9 < wj

    1. Initial program 49.5%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg49.5%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub49.5%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg49.5%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative49.5%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in49.5%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg49.5%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg49.5%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub49.5%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in49.5%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/49.5%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified99.5%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
    4. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{\frac{\frac{x}{e^{wj}} - wj}{wj + 1} + wj} \]
      2. div-inv99.5%

        \[\leadsto \color{blue}{\left(\frac{x}{e^{wj}} - wj\right) \cdot \frac{1}{wj + 1}} + wj \]
      3. fma-def99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{e^{wj}} - wj, \frac{1}{wj + 1}, wj\right)} \]
    5. Applied egg-rr99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{e^{wj}} - wj, \frac{1}{wj + 1}, wj\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq -4.5 \cdot 10^{-9}:\\ \;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\ \mathbf{elif}\;wj \leq 7 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, wj \cdot x, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{e^{wj}} - wj, \frac{1}{wj + 1}, wj\right)\\ \end{array} \]

Alternative 3: 99.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;wj \leq -4.4 \cdot 10^{-9} \lor \neg \left(wj \leq 7.6 \cdot 10^{-9}\right):\\ \;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, wj \cdot x, x\right)\right)\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (if (or (<= wj -4.4e-9) (not (<= wj 7.6e-9)))
   (+ wj (/ (- (/ x (exp wj)) wj) (+ wj 1.0)))
   (fma wj wj (fma -2.0 (* wj x) x))))
double code(double wj, double x) {
	double tmp;
	if ((wj <= -4.4e-9) || !(wj <= 7.6e-9)) {
		tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0));
	} else {
		tmp = fma(wj, wj, fma(-2.0, (wj * x), x));
	}
	return tmp;
}
function code(wj, x)
	tmp = 0.0
	if ((wj <= -4.4e-9) || !(wj <= 7.6e-9))
		tmp = Float64(wj + Float64(Float64(Float64(x / exp(wj)) - wj) / Float64(wj + 1.0)));
	else
		tmp = fma(wj, wj, fma(-2.0, Float64(wj * x), x));
	end
	return tmp
end
code[wj_, x_] := If[Or[LessEqual[wj, -4.4e-9], N[Not[LessEqual[wj, 7.6e-9]], $MachinePrecision]], N[(wj + N[(N[(N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(wj * wj + N[(-2.0 * N[(wj * x), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;wj \leq -4.4 \cdot 10^{-9} \lor \neg \left(wj \leq 7.6 \cdot 10^{-9}\right):\\
\;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, wj \cdot x, x\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if wj < -4.3999999999999997e-9 or 7.60000000000000023e-9 < wj

    1. Initial program 63.7%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg63.7%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub63.7%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg63.7%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative63.7%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in63.7%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg63.7%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg63.7%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub63.7%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in77.9%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/77.9%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified99.3%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]

    if -4.3999999999999997e-9 < wj < 7.60000000000000023e-9

    1. Initial program 78.4%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg78.4%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub78.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg78.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative78.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in78.4%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg78.4%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg78.4%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub78.4%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in78.4%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/78.4%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified78.4%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
    4. Taylor expanded in wj around 0 99.7%

      \[\leadsto \color{blue}{\left(1 - \left(-4 \cdot x + 1.5 \cdot x\right)\right) \cdot {wj}^{2} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)} \]
    5. Taylor expanded in x around 0 99.7%

      \[\leadsto \color{blue}{{wj}^{2}} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
    6. Step-by-step derivation
      1. unpow299.7%

        \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
    7. Simplified99.7%

      \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
    8. Taylor expanded in wj around 0 99.7%

      \[\leadsto \color{blue}{{wj}^{2} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)} \]
    9. Step-by-step derivation
      1. unpow299.7%

        \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
      2. fma-def99.7%

        \[\leadsto wj \cdot wj + \color{blue}{\mathsf{fma}\left(-2, wj \cdot x, x\right)} \]
      3. fma-udef99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, wj \cdot x, x\right)\right)} \]
      4. *-commutative99.7%

        \[\leadsto \mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, \color{blue}{x \cdot wj}, x\right)\right) \]
    10. Simplified99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, x \cdot wj, x\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq -4.4 \cdot 10^{-9} \lor \neg \left(wj \leq 7.6 \cdot 10^{-9}\right):\\ \;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(-2, wj \cdot x, x\right)\right)\\ \end{array} \]

Alternative 4: 99.4% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;wj \leq -1.52 \cdot 10^{-6} \lor \neg \left(wj \leq 5.8 \cdot 10^{-8}\right):\\ \;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \left(x \cdot -4 + x \cdot 1.5\right)\right) \cdot {wj}^{2} + \left(x + -2 \cdot \left(wj \cdot x\right)\right)\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (if (or (<= wj -1.52e-6) (not (<= wj 5.8e-8)))
   (+ wj (/ (- (/ x (exp wj)) wj) (+ wj 1.0)))
   (+
    (* (- 1.0 (+ (* x -4.0) (* x 1.5))) (pow wj 2.0))
    (+ x (* -2.0 (* wj x))))))
double code(double wj, double x) {
	double tmp;
	if ((wj <= -1.52e-6) || !(wj <= 5.8e-8)) {
		tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0));
	} else {
		tmp = ((1.0 - ((x * -4.0) + (x * 1.5))) * pow(wj, 2.0)) + (x + (-2.0 * (wj * x)));
	}
	return tmp;
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((wj <= (-1.52d-6)) .or. (.not. (wj <= 5.8d-8))) then
        tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0d0))
    else
        tmp = ((1.0d0 - ((x * (-4.0d0)) + (x * 1.5d0))) * (wj ** 2.0d0)) + (x + ((-2.0d0) * (wj * x)))
    end if
    code = tmp
end function
public static double code(double wj, double x) {
	double tmp;
	if ((wj <= -1.52e-6) || !(wj <= 5.8e-8)) {
		tmp = wj + (((x / Math.exp(wj)) - wj) / (wj + 1.0));
	} else {
		tmp = ((1.0 - ((x * -4.0) + (x * 1.5))) * Math.pow(wj, 2.0)) + (x + (-2.0 * (wj * x)));
	}
	return tmp;
}
def code(wj, x):
	tmp = 0
	if (wj <= -1.52e-6) or not (wj <= 5.8e-8):
		tmp = wj + (((x / math.exp(wj)) - wj) / (wj + 1.0))
	else:
		tmp = ((1.0 - ((x * -4.0) + (x * 1.5))) * math.pow(wj, 2.0)) + (x + (-2.0 * (wj * x)))
	return tmp
function code(wj, x)
	tmp = 0.0
	if ((wj <= -1.52e-6) || !(wj <= 5.8e-8))
		tmp = Float64(wj + Float64(Float64(Float64(x / exp(wj)) - wj) / Float64(wj + 1.0)));
	else
		tmp = Float64(Float64(Float64(1.0 - Float64(Float64(x * -4.0) + Float64(x * 1.5))) * (wj ^ 2.0)) + Float64(x + Float64(-2.0 * Float64(wj * x))));
	end
	return tmp
end
function tmp_2 = code(wj, x)
	tmp = 0.0;
	if ((wj <= -1.52e-6) || ~((wj <= 5.8e-8)))
		tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0));
	else
		tmp = ((1.0 - ((x * -4.0) + (x * 1.5))) * (wj ^ 2.0)) + (x + (-2.0 * (wj * x)));
	end
	tmp_2 = tmp;
end
code[wj_, x_] := If[Or[LessEqual[wj, -1.52e-6], N[Not[LessEqual[wj, 5.8e-8]], $MachinePrecision]], N[(wj + N[(N[(N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 - N[(N[(x * -4.0), $MachinePrecision] + N[(x * 1.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[wj, 2.0], $MachinePrecision]), $MachinePrecision] + N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;wj \leq -1.52 \cdot 10^{-6} \lor \neg \left(wj \leq 5.8 \cdot 10^{-8}\right):\\
\;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\

\mathbf{else}:\\
\;\;\;\;\left(1 - \left(x \cdot -4 + x \cdot 1.5\right)\right) \cdot {wj}^{2} + \left(x + -2 \cdot \left(wj \cdot x\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if wj < -1.52000000000000006e-6 or 5.8000000000000003e-8 < wj

    1. Initial program 57.8%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg57.8%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub57.8%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg57.8%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative57.8%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in57.8%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg57.8%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg57.8%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub57.8%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in74.3%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/74.3%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified99.3%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]

    if -1.52000000000000006e-6 < wj < 5.8000000000000003e-8

    1. Initial program 78.5%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg78.5%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub78.5%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg78.5%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative78.5%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in78.5%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg78.5%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg78.5%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub78.5%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in78.5%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/78.6%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified78.6%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
    4. Taylor expanded in wj around 0 99.7%

      \[\leadsto \color{blue}{\left(1 - \left(-4 \cdot x + 1.5 \cdot x\right)\right) \cdot {wj}^{2} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq -1.52 \cdot 10^{-6} \lor \neg \left(wj \leq 5.8 \cdot 10^{-8}\right):\\ \;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \left(x \cdot -4 + x \cdot 1.5\right)\right) \cdot {wj}^{2} + \left(x + -2 \cdot \left(wj \cdot x\right)\right)\\ \end{array} \]

Alternative 5: 99.5% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;wj \leq -4.4 \cdot 10^{-9} \lor \neg \left(wj \leq 7.6 \cdot 10^{-9}\right):\\ \;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(x + -2 \cdot \left(wj \cdot x\right)\right) + wj \cdot wj\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (if (or (<= wj -4.4e-9) (not (<= wj 7.6e-9)))
   (+ wj (/ (- (/ x (exp wj)) wj) (+ wj 1.0)))
   (+ (+ x (* -2.0 (* wj x))) (* wj wj))))
double code(double wj, double x) {
	double tmp;
	if ((wj <= -4.4e-9) || !(wj <= 7.6e-9)) {
		tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0));
	} else {
		tmp = (x + (-2.0 * (wj * x))) + (wj * wj);
	}
	return tmp;
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((wj <= (-4.4d-9)) .or. (.not. (wj <= 7.6d-9))) then
        tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0d0))
    else
        tmp = (x + ((-2.0d0) * (wj * x))) + (wj * wj)
    end if
    code = tmp
end function
public static double code(double wj, double x) {
	double tmp;
	if ((wj <= -4.4e-9) || !(wj <= 7.6e-9)) {
		tmp = wj + (((x / Math.exp(wj)) - wj) / (wj + 1.0));
	} else {
		tmp = (x + (-2.0 * (wj * x))) + (wj * wj);
	}
	return tmp;
}
def code(wj, x):
	tmp = 0
	if (wj <= -4.4e-9) or not (wj <= 7.6e-9):
		tmp = wj + (((x / math.exp(wj)) - wj) / (wj + 1.0))
	else:
		tmp = (x + (-2.0 * (wj * x))) + (wj * wj)
	return tmp
function code(wj, x)
	tmp = 0.0
	if ((wj <= -4.4e-9) || !(wj <= 7.6e-9))
		tmp = Float64(wj + Float64(Float64(Float64(x / exp(wj)) - wj) / Float64(wj + 1.0)));
	else
		tmp = Float64(Float64(x + Float64(-2.0 * Float64(wj * x))) + Float64(wj * wj));
	end
	return tmp
end
function tmp_2 = code(wj, x)
	tmp = 0.0;
	if ((wj <= -4.4e-9) || ~((wj <= 7.6e-9)))
		tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0));
	else
		tmp = (x + (-2.0 * (wj * x))) + (wj * wj);
	end
	tmp_2 = tmp;
end
code[wj_, x_] := If[Or[LessEqual[wj, -4.4e-9], N[Not[LessEqual[wj, 7.6e-9]], $MachinePrecision]], N[(wj + N[(N[(N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(wj * wj), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;wj \leq -4.4 \cdot 10^{-9} \lor \neg \left(wj \leq 7.6 \cdot 10^{-9}\right):\\
\;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\

\mathbf{else}:\\
\;\;\;\;\left(x + -2 \cdot \left(wj \cdot x\right)\right) + wj \cdot wj\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if wj < -4.3999999999999997e-9 or 7.60000000000000023e-9 < wj

    1. Initial program 63.7%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg63.7%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub63.7%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg63.7%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative63.7%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in63.7%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg63.7%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg63.7%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub63.7%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in77.9%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/77.9%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified99.3%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]

    if -4.3999999999999997e-9 < wj < 7.60000000000000023e-9

    1. Initial program 78.4%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. sub-neg78.4%

        \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      2. div-sub78.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      3. sub-neg78.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
      4. +-commutative78.4%

        \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
      5. distribute-neg-in78.4%

        \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
      6. remove-double-neg78.4%

        \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
      7. sub-neg78.4%

        \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
      8. div-sub78.4%

        \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
      9. distribute-rgt1-in78.4%

        \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      10. associate-/l/78.4%

        \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
    3. Simplified78.4%

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
    4. Taylor expanded in wj around 0 99.7%

      \[\leadsto \color{blue}{\left(1 - \left(-4 \cdot x + 1.5 \cdot x\right)\right) \cdot {wj}^{2} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)} \]
    5. Taylor expanded in x around 0 99.7%

      \[\leadsto \color{blue}{{wj}^{2}} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
    6. Step-by-step derivation
      1. unpow299.7%

        \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
    7. Simplified99.7%

      \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq -4.4 \cdot 10^{-9} \lor \neg \left(wj \leq 7.6 \cdot 10^{-9}\right):\\ \;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(x + -2 \cdot \left(wj \cdot x\right)\right) + wj \cdot wj\\ \end{array} \]

Alternative 6: 95.6% accurate, 28.5× speedup?

\[\begin{array}{l} \\ \left(x + -2 \cdot \left(wj \cdot x\right)\right) + wj \cdot wj \end{array} \]
(FPCore (wj x) :precision binary64 (+ (+ x (* -2.0 (* wj x))) (* wj wj)))
double code(double wj, double x) {
	return (x + (-2.0 * (wj * x))) + (wj * wj);
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    code = (x + ((-2.0d0) * (wj * x))) + (wj * wj)
end function
public static double code(double wj, double x) {
	return (x + (-2.0 * (wj * x))) + (wj * wj);
}
def code(wj, x):
	return (x + (-2.0 * (wj * x))) + (wj * wj)
function code(wj, x)
	return Float64(Float64(x + Float64(-2.0 * Float64(wj * x))) + Float64(wj * wj))
end
function tmp = code(wj, x)
	tmp = (x + (-2.0 * (wj * x))) + (wj * wj);
end
code[wj_, x_] := N[(N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(wj * wj), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x + -2 \cdot \left(wj \cdot x\right)\right) + wj \cdot wj
\end{array}
Derivation
  1. Initial program 77.6%

    \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
  2. Step-by-step derivation
    1. sub-neg77.6%

      \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
    2. div-sub77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
    3. sub-neg77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
    4. +-commutative77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
    5. distribute-neg-in77.6%

      \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
    6. remove-double-neg77.6%

      \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
    7. sub-neg77.6%

      \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
    8. div-sub77.6%

      \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
    9. distribute-rgt1-in78.3%

      \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
    10. associate-/l/78.4%

      \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
  3. Simplified79.5%

    \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
  4. Taylor expanded in wj around 0 95.5%

    \[\leadsto \color{blue}{\left(1 - \left(-4 \cdot x + 1.5 \cdot x\right)\right) \cdot {wj}^{2} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)} \]
  5. Taylor expanded in x around 0 95.4%

    \[\leadsto \color{blue}{{wj}^{2}} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
  6. Step-by-step derivation
    1. unpow295.4%

      \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
  7. Simplified95.4%

    \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
  8. Final simplification95.4%

    \[\leadsto \left(x + -2 \cdot \left(wj \cdot x\right)\right) + wj \cdot wj \]

Alternative 7: 95.1% accurate, 62.6× speedup?

\[\begin{array}{l} \\ x + wj \cdot wj \end{array} \]
(FPCore (wj x) :precision binary64 (+ x (* wj wj)))
double code(double wj, double x) {
	return x + (wj * wj);
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    code = x + (wj * wj)
end function
public static double code(double wj, double x) {
	return x + (wj * wj);
}
def code(wj, x):
	return x + (wj * wj)
function code(wj, x)
	return Float64(x + Float64(wj * wj))
end
function tmp = code(wj, x)
	tmp = x + (wj * wj);
end
code[wj_, x_] := N[(x + N[(wj * wj), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + wj \cdot wj
\end{array}
Derivation
  1. Initial program 77.6%

    \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
  2. Step-by-step derivation
    1. sub-neg77.6%

      \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
    2. div-sub77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
    3. sub-neg77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
    4. +-commutative77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
    5. distribute-neg-in77.6%

      \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
    6. remove-double-neg77.6%

      \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
    7. sub-neg77.6%

      \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
    8. div-sub77.6%

      \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
    9. distribute-rgt1-in78.3%

      \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
    10. associate-/l/78.4%

      \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
  3. Simplified79.5%

    \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
  4. Taylor expanded in wj around 0 95.5%

    \[\leadsto \color{blue}{\left(1 - \left(-4 \cdot x + 1.5 \cdot x\right)\right) \cdot {wj}^{2} + \left(-2 \cdot \left(wj \cdot x\right) + x\right)} \]
  5. Taylor expanded in x around 0 95.4%

    \[\leadsto \color{blue}{{wj}^{2}} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
  6. Step-by-step derivation
    1. unpow295.4%

      \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
  7. Simplified95.4%

    \[\leadsto \color{blue}{wj \cdot wj} + \left(-2 \cdot \left(wj \cdot x\right) + x\right) \]
  8. Taylor expanded in wj around 0 94.8%

    \[\leadsto wj \cdot wj + \color{blue}{x} \]
  9. Final simplification94.8%

    \[\leadsto x + wj \cdot wj \]

Alternative 8: 4.4% accurate, 313.0× speedup?

\[\begin{array}{l} \\ wj \end{array} \]
(FPCore (wj x) :precision binary64 wj)
double code(double wj, double x) {
	return wj;
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    code = wj
end function
public static double code(double wj, double x) {
	return wj;
}
def code(wj, x):
	return wj
function code(wj, x)
	return wj
end
function tmp = code(wj, x)
	tmp = wj;
end
code[wj_, x_] := wj
\begin{array}{l}

\\
wj
\end{array}
Derivation
  1. Initial program 77.6%

    \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
  2. Step-by-step derivation
    1. sub-neg77.6%

      \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
    2. div-sub77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
    3. sub-neg77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
    4. +-commutative77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
    5. distribute-neg-in77.6%

      \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
    6. remove-double-neg77.6%

      \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
    7. sub-neg77.6%

      \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
    8. div-sub77.6%

      \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
    9. distribute-rgt1-in78.3%

      \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
    10. associate-/l/78.4%

      \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
  3. Simplified79.5%

    \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
  4. Taylor expanded in wj around inf 4.6%

    \[\leadsto \color{blue}{wj} \]
  5. Final simplification4.6%

    \[\leadsto wj \]

Alternative 9: 84.1% accurate, 313.0× speedup?

\[\begin{array}{l} \\ x \end{array} \]
(FPCore (wj x) :precision binary64 x)
double code(double wj, double x) {
	return x;
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    code = x
end function
public static double code(double wj, double x) {
	return x;
}
def code(wj, x):
	return x
function code(wj, x)
	return x
end
function tmp = code(wj, x)
	tmp = x;
end
code[wj_, x_] := x
\begin{array}{l}

\\
x
\end{array}
Derivation
  1. Initial program 77.6%

    \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
  2. Step-by-step derivation
    1. sub-neg77.6%

      \[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]
    2. div-sub77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
    3. sub-neg77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} + \left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right)}\right) \]
    4. +-commutative77.6%

      \[\leadsto wj + \left(-\color{blue}{\left(\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]
    5. distribute-neg-in77.6%

      \[\leadsto wj + \color{blue}{\left(\left(-\left(-\frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\right) + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]
    6. remove-double-neg77.6%

      \[\leadsto wj + \left(\color{blue}{\frac{x}{e^{wj} + wj \cdot e^{wj}}} + \left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right) \]
    7. sub-neg77.6%

      \[\leadsto wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
    8. div-sub77.6%

      \[\leadsto wj + \color{blue}{\frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
    9. distribute-rgt1-in78.3%

      \[\leadsto wj + \frac{x - wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
    10. associate-/l/78.4%

      \[\leadsto wj + \color{blue}{\frac{\frac{x - wj \cdot e^{wj}}{e^{wj}}}{wj + 1}} \]
  3. Simplified79.5%

    \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
  4. Taylor expanded in wj around 0 84.3%

    \[\leadsto \color{blue}{x} \]
  5. Final simplification84.3%

    \[\leadsto x \]

Developer target: 78.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right) \end{array} \]
(FPCore (wj x)
 :precision binary64
 (- wj (- (/ wj (+ wj 1.0)) (/ x (+ (exp wj) (* wj (exp wj)))))))
double code(double wj, double x) {
	return wj - ((wj / (wj + 1.0)) - (x / (exp(wj) + (wj * exp(wj)))));
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    code = wj - ((wj / (wj + 1.0d0)) - (x / (exp(wj) + (wj * exp(wj)))))
end function
public static double code(double wj, double x) {
	return wj - ((wj / (wj + 1.0)) - (x / (Math.exp(wj) + (wj * Math.exp(wj)))));
}
def code(wj, x):
	return wj - ((wj / (wj + 1.0)) - (x / (math.exp(wj) + (wj * math.exp(wj)))))
function code(wj, x)
	return Float64(wj - Float64(Float64(wj / Float64(wj + 1.0)) - Float64(x / Float64(exp(wj) + Float64(wj * exp(wj))))))
end
function tmp = code(wj, x)
	tmp = wj - ((wj / (wj + 1.0)) - (x / (exp(wj) + (wj * exp(wj)))));
end
code[wj_, x_] := N[(wj - N[(N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision] - N[(x / N[(N[Exp[wj], $MachinePrecision] + N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)
\end{array}

Reproduce

?
herbie shell --seed 2023196 
(FPCore (wj x)
  :name "Jmat.Real.lambertw, newton loop step"
  :precision binary64

  :herbie-target
  (- wj (- (/ wj (+ wj 1.0)) (/ x (+ (exp wj) (* wj (exp wj))))))

  (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))