Jmat.Real.lambertw, newton loop step

Percentage Accurate: 77.4% → 99.5%
Time: 13.3s
Alternatives: 13
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 13 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.4% 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.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;wj \leq -1.28 \cdot 10^{-8}:\\ \;\;\;\;wj + \frac{x - wj \cdot e^{wj}}{e^{wj} \cdot \left(wj + 1\right)}\\ \mathbf{elif}\;wj \leq 2.6 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - {wj}^{3}\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (if (<= wj -1.28e-8)
   (+ wj (/ (- x (* wj (exp wj))) (* (exp wj) (+ wj 1.0))))
   (if (<= wj 2.6e-9)
     (- (fma wj wj x) (pow wj 3.0))
     (- wj (/ (- wj (/ x (exp wj))) (+ wj 1.0))))))
double code(double wj, double x) {
	double tmp;
	if (wj <= -1.28e-8) {
		tmp = wj + ((x - (wj * exp(wj))) / (exp(wj) * (wj + 1.0)));
	} else if (wj <= 2.6e-9) {
		tmp = fma(wj, wj, x) - pow(wj, 3.0);
	} else {
		tmp = wj - ((wj - (x / exp(wj))) / (wj + 1.0));
	}
	return tmp;
}
function code(wj, x)
	tmp = 0.0
	if (wj <= -1.28e-8)
		tmp = Float64(wj + Float64(Float64(x - Float64(wj * exp(wj))) / Float64(exp(wj) * Float64(wj + 1.0))));
	elseif (wj <= 2.6e-9)
		tmp = Float64(fma(wj, wj, x) - (wj ^ 3.0));
	else
		tmp = Float64(wj - Float64(Float64(wj - Float64(x / exp(wj))) / Float64(wj + 1.0)));
	end
	return tmp
end
code[wj_, x_] := If[LessEqual[wj, -1.28e-8], N[(wj + N[(N[(x - N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Exp[wj], $MachinePrecision] * N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[wj, 2.6e-9], N[(N[(wj * wj + x), $MachinePrecision] - N[Power[wj, 3.0], $MachinePrecision]), $MachinePrecision], N[(wj - N[(N[(wj - N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\


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

    1. Initial program 63.8%

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

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

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

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

    if -1.28000000000000005e-8 < wj < 2.6000000000000001e-9

    1. Initial program 79.1%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in79.1%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*79.1%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses79.1%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity79.1%

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

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

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

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

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

        \[\leadsto x + \color{blue}{\left({wj}^{2} + -1 \cdot {wj}^{3}\right)} \]
      2. neg-mul-199.4%

        \[\leadsto x + \left({wj}^{2} + \color{blue}{\left(-{wj}^{3}\right)}\right) \]
      3. unsub-neg99.4%

        \[\leadsto x + \color{blue}{\left({wj}^{2} - {wj}^{3}\right)} \]
    9. Simplified99.4%

      \[\leadsto x + \color{blue}{\left({wj}^{2} - {wj}^{3}\right)} \]
    10. Taylor expanded in x around 0 99.4%

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

        \[\leadsto \color{blue}{\left({wj}^{2} + x\right)} - {wj}^{3} \]
      2. unpow299.4%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj, x\right)} - {wj}^{3} \]
    12. Simplified99.4%

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

    if 2.6000000000000001e-9 < wj

    1. Initial program 65.9%

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

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*65.7%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses95.7%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity95.7%

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

      \[\leadsto \color{blue}{wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}} \]
    4. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification98.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq -1.28 \cdot 10^{-8}:\\ \;\;\;\;wj + \frac{x - wj \cdot e^{wj}}{e^{wj} \cdot \left(wj + 1\right)}\\ \mathbf{elif}\;wj \leq 2.6 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - {wj}^{3}\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 98.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := wj \cdot e^{wj}\\ t_1 := x \cdot -4 + x \cdot 1.5\\ \mathbf{if}\;wj + \frac{x - t\_0}{e^{wj} + t\_0} \leq 5 \cdot 10^{-18}:\\ \;\;\;\;x + \left(-2 \cdot \left(wj \cdot x\right) + \left({wj}^{3} \cdot \left(-1 - \left(x \cdot -3 + \left(-2 \cdot t\_1 + x \cdot 0.6666666666666666\right)\right)\right) + {wj}^{2} \cdot \left(1 - t\_1\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (let* ((t_0 (* wj (exp wj))) (t_1 (+ (* x -4.0) (* x 1.5))))
   (if (<= (+ wj (/ (- x t_0) (+ (exp wj) t_0))) 5e-18)
     (+
      x
      (+
       (* -2.0 (* wj x))
       (+
        (*
         (pow wj 3.0)
         (- -1.0 (+ (* x -3.0) (+ (* -2.0 t_1) (* x 0.6666666666666666)))))
        (* (pow wj 2.0) (- 1.0 t_1)))))
     (- wj (/ (- wj (/ x (exp wj))) (+ wj 1.0))))))
double code(double wj, double x) {
	double t_0 = wj * exp(wj);
	double t_1 = (x * -4.0) + (x * 1.5);
	double tmp;
	if ((wj + ((x - t_0) / (exp(wj) + t_0))) <= 5e-18) {
		tmp = x + ((-2.0 * (wj * x)) + ((pow(wj, 3.0) * (-1.0 - ((x * -3.0) + ((-2.0 * t_1) + (x * 0.6666666666666666))))) + (pow(wj, 2.0) * (1.0 - t_1))));
	} else {
		tmp = wj - ((wj - (x / exp(wj))) / (wj + 1.0));
	}
	return tmp;
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = wj * exp(wj)
    t_1 = (x * (-4.0d0)) + (x * 1.5d0)
    if ((wj + ((x - t_0) / (exp(wj) + t_0))) <= 5d-18) then
        tmp = x + (((-2.0d0) * (wj * x)) + (((wj ** 3.0d0) * ((-1.0d0) - ((x * (-3.0d0)) + (((-2.0d0) * t_1) + (x * 0.6666666666666666d0))))) + ((wj ** 2.0d0) * (1.0d0 - t_1))))
    else
        tmp = wj - ((wj - (x / exp(wj))) / (wj + 1.0d0))
    end if
    code = tmp
end function
public static double code(double wj, double x) {
	double t_0 = wj * Math.exp(wj);
	double t_1 = (x * -4.0) + (x * 1.5);
	double tmp;
	if ((wj + ((x - t_0) / (Math.exp(wj) + t_0))) <= 5e-18) {
		tmp = x + ((-2.0 * (wj * x)) + ((Math.pow(wj, 3.0) * (-1.0 - ((x * -3.0) + ((-2.0 * t_1) + (x * 0.6666666666666666))))) + (Math.pow(wj, 2.0) * (1.0 - t_1))));
	} else {
		tmp = wj - ((wj - (x / Math.exp(wj))) / (wj + 1.0));
	}
	return tmp;
}
def code(wj, x):
	t_0 = wj * math.exp(wj)
	t_1 = (x * -4.0) + (x * 1.5)
	tmp = 0
	if (wj + ((x - t_0) / (math.exp(wj) + t_0))) <= 5e-18:
		tmp = x + ((-2.0 * (wj * x)) + ((math.pow(wj, 3.0) * (-1.0 - ((x * -3.0) + ((-2.0 * t_1) + (x * 0.6666666666666666))))) + (math.pow(wj, 2.0) * (1.0 - t_1))))
	else:
		tmp = wj - ((wj - (x / math.exp(wj))) / (wj + 1.0))
	return tmp
function code(wj, x)
	t_0 = Float64(wj * exp(wj))
	t_1 = Float64(Float64(x * -4.0) + Float64(x * 1.5))
	tmp = 0.0
	if (Float64(wj + Float64(Float64(x - t_0) / Float64(exp(wj) + t_0))) <= 5e-18)
		tmp = Float64(x + Float64(Float64(-2.0 * Float64(wj * x)) + Float64(Float64((wj ^ 3.0) * Float64(-1.0 - Float64(Float64(x * -3.0) + Float64(Float64(-2.0 * t_1) + Float64(x * 0.6666666666666666))))) + Float64((wj ^ 2.0) * Float64(1.0 - t_1)))));
	else
		tmp = Float64(wj - Float64(Float64(wj - Float64(x / exp(wj))) / Float64(wj + 1.0)));
	end
	return tmp
end
function tmp_2 = code(wj, x)
	t_0 = wj * exp(wj);
	t_1 = (x * -4.0) + (x * 1.5);
	tmp = 0.0;
	if ((wj + ((x - t_0) / (exp(wj) + t_0))) <= 5e-18)
		tmp = x + ((-2.0 * (wj * x)) + (((wj ^ 3.0) * (-1.0 - ((x * -3.0) + ((-2.0 * t_1) + (x * 0.6666666666666666))))) + ((wj ^ 2.0) * (1.0 - t_1))));
	else
		tmp = wj - ((wj - (x / exp(wj))) / (wj + 1.0));
	end
	tmp_2 = tmp;
end
code[wj_, x_] := Block[{t$95$0 = N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * -4.0), $MachinePrecision] + N[(x * 1.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(wj + N[(N[(x - t$95$0), $MachinePrecision] / N[(N[Exp[wj], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-18], N[(x + N[(N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[wj, 3.0], $MachinePrecision] * N[(-1.0 - N[(N[(x * -3.0), $MachinePrecision] + N[(N[(-2.0 * t$95$1), $MachinePrecision] + N[(x * 0.6666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[wj, 2.0], $MachinePrecision] * N[(1.0 - t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(wj - N[(N[(wj - N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := wj \cdot e^{wj}\\
t_1 := x \cdot -4 + x \cdot 1.5\\
\mathbf{if}\;wj + \frac{x - t\_0}{e^{wj} + t\_0} \leq 5 \cdot 10^{-18}:\\
\;\;\;\;x + \left(-2 \cdot \left(wj \cdot x\right) + \left({wj}^{3} \cdot \left(-1 - \left(x \cdot -3 + \left(-2 \cdot t\_1 + x \cdot 0.6666666666666666\right)\right)\right) + {wj}^{2} \cdot \left(1 - t\_1\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) < 5.00000000000000036e-18

    1. Initial program 72.0%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in72.0%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*72.0%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses72.0%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity72.0%

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

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

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

    if 5.00000000000000036e-18 < (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj)))))

    1. Initial program 92.7%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in94.0%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*92.7%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses97.9%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity97.9%

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

      \[\leadsto \color{blue}{wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}} \]
    4. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification98.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj + \frac{x - wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} \leq 5 \cdot 10^{-18}:\\ \;\;\;\;x + \left(-2 \cdot \left(wj \cdot x\right) + \left({wj}^{3} \cdot \left(-1 - \left(x \cdot -3 + \left(-2 \cdot \left(x \cdot -4 + x \cdot 1.5\right) + x \cdot 0.6666666666666666\right)\right)\right) + {wj}^{2} \cdot \left(1 - \left(x \cdot -4 + x \cdot 1.5\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.0% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;wj \leq 3.6 \cdot 10^{-6}:\\
\;\;\;\;x + \left(-2 \cdot \left(wj \cdot x\right) + \left({wj}^{2} \cdot \left(1 - \left(x \cdot -4 + x \cdot 1.5\right)\right) - {wj}^{3}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\


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

    1. Initial program 78.8%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in79.2%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*78.8%

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

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

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

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

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

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

    if 3.59999999999999984e-6 < wj

    1. Initial program 62.1%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in62.1%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*62.1%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses95.4%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity95.4%

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

      \[\leadsto \color{blue}{wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}} \]
    4. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification97.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq 3.6 \cdot 10^{-6}:\\ \;\;\;\;x + \left(-2 \cdot \left(wj \cdot x\right) + \left({wj}^{2} \cdot \left(1 - \left(x \cdot -4 + x \cdot 1.5\right)\right) - {wj}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 99.5% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 65.1%

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

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*65.0%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses90.4%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity90.4%

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

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

    if -3.7e-9 < wj < 4.9000000000000002e-8

    1. Initial program 79.1%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in79.1%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*79.1%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses79.1%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity79.1%

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

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

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

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

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

        \[\leadsto x + \color{blue}{\left({wj}^{2} + -1 \cdot {wj}^{3}\right)} \]
      2. neg-mul-199.4%

        \[\leadsto x + \left({wj}^{2} + \color{blue}{\left(-{wj}^{3}\right)}\right) \]
      3. unsub-neg99.4%

        \[\leadsto x + \color{blue}{\left({wj}^{2} - {wj}^{3}\right)} \]
    9. Simplified99.4%

      \[\leadsto x + \color{blue}{\left({wj}^{2} - {wj}^{3}\right)} \]
    10. Taylor expanded in x around 0 99.4%

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

        \[\leadsto \color{blue}{\left({wj}^{2} + x\right)} - {wj}^{3} \]
      2. unpow299.4%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj, x\right)} - {wj}^{3} \]
    12. Simplified99.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq -3.7 \cdot 10^{-9} \lor \neg \left(wj \leq 4.9 \cdot 10^{-8}\right):\\ \;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - {wj}^{3}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.4% accurate, 2.4× speedup?

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

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

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


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

    1. Initial program 62.8%

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

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*62.8%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses89.8%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity89.8%

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

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

    if -1e-8 < wj < 1.78000000000000006e-7

    1. Initial program 79.2%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in79.2%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*79.2%

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

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity79.2%

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

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

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

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

Alternative 6: 99.3% accurate, 2.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if wj < -4.60000000000000027e-11 or 2.15000000000000001e-11 < wj

    1. Initial program 68.4%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in73.1%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*68.4%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses86.9%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity86.9%

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

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

    if -4.60000000000000027e-11 < wj < 2.15000000000000001e-11

    1. Initial program 79.1%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in79.1%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*79.2%

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

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity79.2%

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

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

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

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

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

        \[\leadsto x + \color{blue}{\left({wj}^{2} + -1 \cdot {wj}^{3}\right)} \]
      2. neg-mul-199.8%

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

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

      \[\leadsto x + \color{blue}{\left({wj}^{2} - {wj}^{3}\right)} \]
    10. Taylor expanded in wj around 0 99.5%

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

        \[\leadsto \color{blue}{{wj}^{2} + x} \]
      2. unpow299.5%

        \[\leadsto \color{blue}{wj \cdot wj} + x \]
      3. fma-def99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj, x\right)} \]
    12. Simplified99.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq -4.6 \cdot 10^{-11} \lor \neg \left(wj \leq 2.15 \cdot 10^{-11}\right):\\ \;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 85.6% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := wj + \frac{\left(x - wj \cdot x\right) - wj}{wj + 1}\\ \mathbf{if}\;wj \leq -1.5 \cdot 10^{-29}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;wj \leq 5.2 \cdot 10^{-49}:\\ \;\;\;\;x\\ \mathbf{elif}\;wj \leq 2.3 \cdot 10^{-17}:\\ \;\;\;\;{wj}^{2}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (let* ((t_0 (+ wj (/ (- (- x (* wj x)) wj) (+ wj 1.0)))))
   (if (<= wj -1.5e-29)
     t_0
     (if (<= wj 5.2e-49) x (if (<= wj 2.3e-17) (pow wj 2.0) t_0)))))
double code(double wj, double x) {
	double t_0 = wj + (((x - (wj * x)) - wj) / (wj + 1.0));
	double tmp;
	if (wj <= -1.5e-29) {
		tmp = t_0;
	} else if (wj <= 5.2e-49) {
		tmp = x;
	} else if (wj <= 2.3e-17) {
		tmp = pow(wj, 2.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = wj + (((x - (wj * x)) - wj) / (wj + 1.0d0))
    if (wj <= (-1.5d-29)) then
        tmp = t_0
    else if (wj <= 5.2d-49) then
        tmp = x
    else if (wj <= 2.3d-17) then
        tmp = wj ** 2.0d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double wj, double x) {
	double t_0 = wj + (((x - (wj * x)) - wj) / (wj + 1.0));
	double tmp;
	if (wj <= -1.5e-29) {
		tmp = t_0;
	} else if (wj <= 5.2e-49) {
		tmp = x;
	} else if (wj <= 2.3e-17) {
		tmp = Math.pow(wj, 2.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(wj, x):
	t_0 = wj + (((x - (wj * x)) - wj) / (wj + 1.0))
	tmp = 0
	if wj <= -1.5e-29:
		tmp = t_0
	elif wj <= 5.2e-49:
		tmp = x
	elif wj <= 2.3e-17:
		tmp = math.pow(wj, 2.0)
	else:
		tmp = t_0
	return tmp
function code(wj, x)
	t_0 = Float64(wj + Float64(Float64(Float64(x - Float64(wj * x)) - wj) / Float64(wj + 1.0)))
	tmp = 0.0
	if (wj <= -1.5e-29)
		tmp = t_0;
	elseif (wj <= 5.2e-49)
		tmp = x;
	elseif (wj <= 2.3e-17)
		tmp = wj ^ 2.0;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(wj, x)
	t_0 = wj + (((x - (wj * x)) - wj) / (wj + 1.0));
	tmp = 0.0;
	if (wj <= -1.5e-29)
		tmp = t_0;
	elseif (wj <= 5.2e-49)
		tmp = x;
	elseif (wj <= 2.3e-17)
		tmp = wj ^ 2.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[wj_, x_] := Block[{t$95$0 = N[(wj + N[(N[(N[(x - N[(wj * x), $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[wj, -1.5e-29], t$95$0, If[LessEqual[wj, 5.2e-49], x, If[LessEqual[wj, 2.3e-17], N[Power[wj, 2.0], $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := wj + \frac{\left(x - wj \cdot x\right) - wj}{wj + 1}\\
\mathbf{if}\;wj \leq -1.5 \cdot 10^{-29}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;wj \leq 5.2 \cdot 10^{-49}:\\
\;\;\;\;x\\

\mathbf{elif}\;wj \leq 2.3 \cdot 10^{-17}:\\
\;\;\;\;{wj}^{2}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if wj < -1.5000000000000001e-29 or 2.30000000000000009e-17 < wj

    1. Initial program 70.4%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in73.0%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*70.6%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses81.1%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity81.1%

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

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

      \[\leadsto wj - \frac{wj - \color{blue}{\left(x + -1 \cdot \left(wj \cdot x\right)\right)}}{wj + 1} \]
    6. Step-by-step derivation
      1. associate-*r*70.6%

        \[\leadsto wj - \frac{wj - \left(x + \color{blue}{\left(-1 \cdot wj\right) \cdot x}\right)}{wj + 1} \]
      2. neg-mul-170.6%

        \[\leadsto wj - \frac{wj - \left(x + \color{blue}{\left(-wj\right)} \cdot x\right)}{wj + 1} \]
    7. Simplified70.6%

      \[\leadsto wj - \frac{wj - \color{blue}{\left(x + \left(-wj\right) \cdot x\right)}}{wj + 1} \]

    if -1.5000000000000001e-29 < wj < 5.1999999999999999e-49

    1. Initial program 83.0%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in83.0%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*83.0%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses83.0%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity83.0%

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

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

      \[\leadsto \color{blue}{x} \]

    if 5.1999999999999999e-49 < wj < 2.30000000000000009e-17

    1. Initial program 25.9%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 3.3%

      \[\leadsto \color{blue}{wj - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}} \]
    4. Step-by-step derivation
      1. distribute-rgt1-in3.3%

        \[\leadsto wj - \frac{wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}} \]
      2. *-commutative3.3%

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

      \[\leadsto \color{blue}{wj - \frac{wj \cdot e^{wj}}{e^{wj} \cdot \left(wj + 1\right)}} \]
    6. Taylor expanded in wj around 0 77.8%

      \[\leadsto \color{blue}{-1 \cdot {wj}^{3} + {wj}^{2}} \]
    7. Step-by-step derivation
      1. +-commutative77.8%

        \[\leadsto \color{blue}{{wj}^{2} + -1 \cdot {wj}^{3}} \]
      2. mul-1-neg77.8%

        \[\leadsto {wj}^{2} + \color{blue}{\left(-{wj}^{3}\right)} \]
      3. unsub-neg77.8%

        \[\leadsto \color{blue}{{wj}^{2} - {wj}^{3}} \]
    8. Simplified77.8%

      \[\leadsto \color{blue}{{wj}^{2} - {wj}^{3}} \]
    9. Taylor expanded in wj around 0 77.8%

      \[\leadsto \color{blue}{{wj}^{2}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification89.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq -1.5 \cdot 10^{-29}:\\ \;\;\;\;wj + \frac{\left(x - wj \cdot x\right) - wj}{wj + 1}\\ \mathbf{elif}\;wj \leq 5.2 \cdot 10^{-49}:\\ \;\;\;\;x\\ \mathbf{elif}\;wj \leq 2.3 \cdot 10^{-17}:\\ \;\;\;\;{wj}^{2}\\ \mathbf{else}:\\ \;\;\;\;wj + \frac{\left(x - wj \cdot x\right) - wj}{wj + 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 96.4% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;wj \leq 2.7 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, x\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{wj + 1}\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (if (<= wj 2.7e-5) (fma wj wj x) (- wj (/ wj (+ wj 1.0)))))
double code(double wj, double x) {
	double tmp;
	if (wj <= 2.7e-5) {
		tmp = fma(wj, wj, x);
	} else {
		tmp = wj - (wj / (wj + 1.0));
	}
	return tmp;
}
function code(wj, x)
	tmp = 0.0
	if (wj <= 2.7e-5)
		tmp = fma(wj, wj, x);
	else
		tmp = Float64(wj - Float64(wj / Float64(wj + 1.0)));
	end
	return tmp
end
code[wj_, x_] := If[LessEqual[wj, 2.7e-5], N[(wj * wj + x), $MachinePrecision], N[(wj - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;wj \leq 2.7 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, x\right)\\

\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if wj < 2.6999999999999999e-5

    1. Initial program 78.8%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in79.2%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*78.8%

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

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

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

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

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

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

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

        \[\leadsto x + \color{blue}{\left({wj}^{2} + -1 \cdot {wj}^{3}\right)} \]
      2. neg-mul-197.1%

        \[\leadsto x + \left({wj}^{2} + \color{blue}{\left(-{wj}^{3}\right)}\right) \]
      3. unsub-neg97.1%

        \[\leadsto x + \color{blue}{\left({wj}^{2} - {wj}^{3}\right)} \]
    9. Simplified97.1%

      \[\leadsto x + \color{blue}{\left({wj}^{2} - {wj}^{3}\right)} \]
    10. Taylor expanded in wj around 0 96.4%

      \[\leadsto \color{blue}{x + {wj}^{2}} \]
    11. Step-by-step derivation
      1. +-commutative96.4%

        \[\leadsto \color{blue}{{wj}^{2} + x} \]
      2. unpow296.4%

        \[\leadsto \color{blue}{wj \cdot wj} + x \]
      3. fma-def96.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj, x\right)} \]
    12. Simplified96.4%

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

    if 2.6999999999999999e-5 < wj

    1. Initial program 62.1%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in62.1%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*62.1%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses95.4%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity95.4%

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

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

      \[\leadsto \color{blue}{wj - \frac{wj}{1 + wj}} \]
    6. Step-by-step derivation
      1. +-commutative84.5%

        \[\leadsto wj - \frac{wj}{\color{blue}{wj + 1}} \]
    7. Simplified84.5%

      \[\leadsto \color{blue}{wj - \frac{wj}{wj + 1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq 2.7 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, x\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{wj + 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 86.7% accurate, 17.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;wj \leq -1.35 \cdot 10^{-29}:\\ \;\;\;\;wj + \frac{\left(x - wj \cdot x\right) - wj}{wj + 1}\\ \mathbf{elif}\;wj \leq 2 \cdot 10^{-6}:\\ \;\;\;\;x + -2 \cdot \left(wj \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{wj + 1}\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (if (<= wj -1.35e-29)
   (+ wj (/ (- (- x (* wj x)) wj) (+ wj 1.0)))
   (if (<= wj 2e-6) (+ x (* -2.0 (* wj x))) (- wj (/ wj (+ wj 1.0))))))
double code(double wj, double x) {
	double tmp;
	if (wj <= -1.35e-29) {
		tmp = wj + (((x - (wj * x)) - wj) / (wj + 1.0));
	} else if (wj <= 2e-6) {
		tmp = x + (-2.0 * (wj * x));
	} else {
		tmp = wj - (wj / (wj + 1.0));
	}
	return tmp;
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    real(8) :: tmp
    if (wj <= (-1.35d-29)) then
        tmp = wj + (((x - (wj * x)) - wj) / (wj + 1.0d0))
    else if (wj <= 2d-6) then
        tmp = x + ((-2.0d0) * (wj * x))
    else
        tmp = wj - (wj / (wj + 1.0d0))
    end if
    code = tmp
end function
public static double code(double wj, double x) {
	double tmp;
	if (wj <= -1.35e-29) {
		tmp = wj + (((x - (wj * x)) - wj) / (wj + 1.0));
	} else if (wj <= 2e-6) {
		tmp = x + (-2.0 * (wj * x));
	} else {
		tmp = wj - (wj / (wj + 1.0));
	}
	return tmp;
}
def code(wj, x):
	tmp = 0
	if wj <= -1.35e-29:
		tmp = wj + (((x - (wj * x)) - wj) / (wj + 1.0))
	elif wj <= 2e-6:
		tmp = x + (-2.0 * (wj * x))
	else:
		tmp = wj - (wj / (wj + 1.0))
	return tmp
function code(wj, x)
	tmp = 0.0
	if (wj <= -1.35e-29)
		tmp = Float64(wj + Float64(Float64(Float64(x - Float64(wj * x)) - wj) / Float64(wj + 1.0)));
	elseif (wj <= 2e-6)
		tmp = Float64(x + Float64(-2.0 * Float64(wj * x)));
	else
		tmp = Float64(wj - Float64(wj / Float64(wj + 1.0)));
	end
	return tmp
end
function tmp_2 = code(wj, x)
	tmp = 0.0;
	if (wj <= -1.35e-29)
		tmp = wj + (((x - (wj * x)) - wj) / (wj + 1.0));
	elseif (wj <= 2e-6)
		tmp = x + (-2.0 * (wj * x));
	else
		tmp = wj - (wj / (wj + 1.0));
	end
	tmp_2 = tmp;
end
code[wj_, x_] := If[LessEqual[wj, -1.35e-29], N[(wj + N[(N[(N[(x - N[(wj * x), $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[wj, 2e-6], N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(wj - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;wj \leq -1.35 \cdot 10^{-29}:\\
\;\;\;\;wj + \frac{\left(x - wj \cdot x\right) - wj}{wj + 1}\\

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

\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\


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

    1. Initial program 72.6%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in77.2%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*72.6%

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

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity77.2%

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

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

      \[\leadsto wj - \frac{wj - \color{blue}{\left(x + -1 \cdot \left(wj \cdot x\right)\right)}}{wj + 1} \]
    6. Step-by-step derivation
      1. associate-*r*69.8%

        \[\leadsto wj - \frac{wj - \left(x + \color{blue}{\left(-1 \cdot wj\right) \cdot x}\right)}{wj + 1} \]
      2. neg-mul-169.8%

        \[\leadsto wj - \frac{wj - \left(x + \color{blue}{\left(-wj\right)} \cdot x\right)}{wj + 1} \]
    7. Simplified69.8%

      \[\leadsto wj - \frac{wj - \color{blue}{\left(x + \left(-wj\right) \cdot x\right)}}{wj + 1} \]

    if -1.35000000000000011e-29 < wj < 1.99999999999999991e-6

    1. Initial program 79.4%

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

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*79.5%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses79.5%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity79.5%

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

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

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

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

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

    if 1.99999999999999991e-6 < wj

    1. Initial program 62.1%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in62.1%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*62.1%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses95.4%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity95.4%

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

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

      \[\leadsto \color{blue}{wj - \frac{wj}{1 + wj}} \]
    6. Step-by-step derivation
      1. +-commutative84.5%

        \[\leadsto wj - \frac{wj}{\color{blue}{wj + 1}} \]
    7. Simplified84.5%

      \[\leadsto \color{blue}{wj - \frac{wj}{wj + 1}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification86.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq -1.35 \cdot 10^{-29}:\\ \;\;\;\;wj + \frac{\left(x - wj \cdot x\right) - wj}{wj + 1}\\ \mathbf{elif}\;wj \leq 2 \cdot 10^{-6}:\\ \;\;\;\;x + -2 \cdot \left(wj \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{wj + 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 85.9% accurate, 26.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;wj \leq 1.7 \cdot 10^{-5}:\\ \;\;\;\;x + -2 \cdot \left(wj \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{wj + 1}\\ \end{array} \end{array} \]
(FPCore (wj x)
 :precision binary64
 (if (<= wj 1.7e-5) (+ x (* -2.0 (* wj x))) (- wj (/ wj (+ wj 1.0)))))
double code(double wj, double x) {
	double tmp;
	if (wj <= 1.7e-5) {
		tmp = x + (-2.0 * (wj * x));
	} else {
		tmp = wj - (wj / (wj + 1.0));
	}
	return tmp;
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    real(8) :: tmp
    if (wj <= 1.7d-5) then
        tmp = x + ((-2.0d0) * (wj * x))
    else
        tmp = wj - (wj / (wj + 1.0d0))
    end if
    code = tmp
end function
public static double code(double wj, double x) {
	double tmp;
	if (wj <= 1.7e-5) {
		tmp = x + (-2.0 * (wj * x));
	} else {
		tmp = wj - (wj / (wj + 1.0));
	}
	return tmp;
}
def code(wj, x):
	tmp = 0
	if wj <= 1.7e-5:
		tmp = x + (-2.0 * (wj * x))
	else:
		tmp = wj - (wj / (wj + 1.0))
	return tmp
function code(wj, x)
	tmp = 0.0
	if (wj <= 1.7e-5)
		tmp = Float64(x + Float64(-2.0 * Float64(wj * x)));
	else
		tmp = Float64(wj - Float64(wj / Float64(wj + 1.0)));
	end
	return tmp
end
function tmp_2 = code(wj, x)
	tmp = 0.0;
	if (wj <= 1.7e-5)
		tmp = x + (-2.0 * (wj * x));
	else
		tmp = wj - (wj / (wj + 1.0));
	end
	tmp_2 = tmp;
end
code[wj_, x_] := If[LessEqual[wj, 1.7e-5], N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(wj - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;wj \leq 1.7 \cdot 10^{-5}:\\
\;\;\;\;x + -2 \cdot \left(wj \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if wj < 1.7e-5

    1. Initial program 78.8%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in79.2%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*78.8%

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

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

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

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

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

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

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

    if 1.7e-5 < wj

    1. Initial program 62.1%

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Step-by-step derivation
      1. distribute-rgt1-in62.1%

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

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

        \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
      4. associate-/l*62.1%

        \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
      5. *-inverses95.4%

        \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
      6. /-rgt-identity95.4%

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

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

      \[\leadsto \color{blue}{wj - \frac{wj}{1 + wj}} \]
    6. Step-by-step derivation
      1. +-commutative84.5%

        \[\leadsto wj - \frac{wj}{\color{blue}{wj + 1}} \]
    7. Simplified84.5%

      \[\leadsto \color{blue}{wj - \frac{wj}{wj + 1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq 1.7 \cdot 10^{-5}:\\ \;\;\;\;x + -2 \cdot \left(wj \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{wj + 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 84.5% accurate, 44.7× speedup?

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

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

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

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

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

      \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
    4. associate-/l*78.2%

      \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
    5. *-inverses79.8%

      \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
    6. /-rgt-identity79.8%

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

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

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

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

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

    \[\leadsto x + -2 \cdot \left(wj \cdot x\right) \]
  9. Add Preprocessing

Alternative 12: 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 78.2%

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

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

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

      \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
    4. associate-/l*78.2%

      \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
    5. *-inverses79.8%

      \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
    6. /-rgt-identity79.8%

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

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

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

    \[\leadsto wj \]
  7. Add Preprocessing

Alternative 13: 83.9% 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 78.2%

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

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

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

      \[\leadsto wj - \frac{\color{blue}{\frac{wj \cdot e^{wj}}{e^{wj}} - \frac{x}{e^{wj}}}}{wj + 1} \]
    4. associate-/l*78.2%

      \[\leadsto wj - \frac{\color{blue}{\frac{wj}{\frac{e^{wj}}{e^{wj}}}} - \frac{x}{e^{wj}}}{wj + 1} \]
    5. *-inverses79.8%

      \[\leadsto wj - \frac{\frac{wj}{\color{blue}{1}} - \frac{x}{e^{wj}}}{wj + 1} \]
    6. /-rgt-identity79.8%

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

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

    \[\leadsto \color{blue}{x} \]
  6. Final simplification81.6%

    \[\leadsto x \]
  7. Add Preprocessing

Developer target: 78.4% 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 2024040 
(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))))))