Average Error: 13.3 → 1.1
Time: 14.0s
Precision: binary64
Cost: 15684
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
\[\begin{array}{l} t_0 := x \cdot 4 + x \cdot -1.5\\ \mathbf{if}\;wj \leq 3.1 \cdot 10^{-5}:\\ \;\;\;\;{wj}^{3} \cdot \left(x \cdot -0.6666666666666666 + \left(x \cdot 3 + \left(-1 + -2 \cdot t_0\right)\right)\right) + \left(\left(1 + t_0\right) \cdot {wj}^{2} + \left(x + -2 \cdot \left(wj \cdot x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-wj\right) \cdot \mathsf{expm1}\left(-\mathsf{log1p}\left(wj\right)\right)\\ \end{array} \]
(FPCore (wj x)
 :precision binary64
 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x)
 :precision binary64
 (let* ((t_0 (+ (* x 4.0) (* x -1.5))))
   (if (<= wj 3.1e-5)
     (+
      (*
       (pow wj 3.0)
       (+ (* x -0.6666666666666666) (+ (* x 3.0) (+ -1.0 (* -2.0 t_0)))))
      (+ (* (+ 1.0 t_0) (pow wj 2.0)) (+ x (* -2.0 (* wj x)))))
     (* (- wj) (expm1 (- (log1p wj)))))))
double code(double wj, double x) {
	return wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))));
}
double code(double wj, double x) {
	double t_0 = (x * 4.0) + (x * -1.5);
	double tmp;
	if (wj <= 3.1e-5) {
		tmp = (pow(wj, 3.0) * ((x * -0.6666666666666666) + ((x * 3.0) + (-1.0 + (-2.0 * t_0))))) + (((1.0 + t_0) * pow(wj, 2.0)) + (x + (-2.0 * (wj * x))));
	} else {
		tmp = -wj * expm1(-log1p(wj));
	}
	return tmp;
}
public static double code(double wj, double x) {
	return wj - (((wj * Math.exp(wj)) - x) / (Math.exp(wj) + (wj * Math.exp(wj))));
}
public static double code(double wj, double x) {
	double t_0 = (x * 4.0) + (x * -1.5);
	double tmp;
	if (wj <= 3.1e-5) {
		tmp = (Math.pow(wj, 3.0) * ((x * -0.6666666666666666) + ((x * 3.0) + (-1.0 + (-2.0 * t_0))))) + (((1.0 + t_0) * Math.pow(wj, 2.0)) + (x + (-2.0 * (wj * x))));
	} else {
		tmp = -wj * Math.expm1(-Math.log1p(wj));
	}
	return tmp;
}
def code(wj, x):
	return wj - (((wj * math.exp(wj)) - x) / (math.exp(wj) + (wj * math.exp(wj))))
def code(wj, x):
	t_0 = (x * 4.0) + (x * -1.5)
	tmp = 0
	if wj <= 3.1e-5:
		tmp = (math.pow(wj, 3.0) * ((x * -0.6666666666666666) + ((x * 3.0) + (-1.0 + (-2.0 * t_0))))) + (((1.0 + t_0) * math.pow(wj, 2.0)) + (x + (-2.0 * (wj * x))))
	else:
		tmp = -wj * math.expm1(-math.log1p(wj))
	return tmp
function code(wj, x)
	return Float64(wj - Float64(Float64(Float64(wj * exp(wj)) - x) / Float64(exp(wj) + Float64(wj * exp(wj)))))
end
function code(wj, x)
	t_0 = Float64(Float64(x * 4.0) + Float64(x * -1.5))
	tmp = 0.0
	if (wj <= 3.1e-5)
		tmp = Float64(Float64((wj ^ 3.0) * Float64(Float64(x * -0.6666666666666666) + Float64(Float64(x * 3.0) + Float64(-1.0 + Float64(-2.0 * t_0))))) + Float64(Float64(Float64(1.0 + t_0) * (wj ^ 2.0)) + Float64(x + Float64(-2.0 * Float64(wj * x)))));
	else
		tmp = Float64(Float64(-wj) * expm1(Float64(-log1p(wj))));
	end
	return tmp
end
code[wj_, x_] := N[(wj - N[(N[(N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] / N[(N[Exp[wj], $MachinePrecision] + N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[wj_, x_] := Block[{t$95$0 = N[(N[(x * 4.0), $MachinePrecision] + N[(x * -1.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[wj, 3.1e-5], N[(N[(N[Power[wj, 3.0], $MachinePrecision] * N[(N[(x * -0.6666666666666666), $MachinePrecision] + N[(N[(x * 3.0), $MachinePrecision] + N[(-1.0 + N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(1.0 + t$95$0), $MachinePrecision] * N[Power[wj, 2.0], $MachinePrecision]), $MachinePrecision] + N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-wj) * N[(Exp[(-N[Log[1 + wj], $MachinePrecision])] - 1), $MachinePrecision]), $MachinePrecision]]]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
t_0 := x \cdot 4 + x \cdot -1.5\\
\mathbf{if}\;wj \leq 3.1 \cdot 10^{-5}:\\
\;\;\;\;{wj}^{3} \cdot \left(x \cdot -0.6666666666666666 + \left(x \cdot 3 + \left(-1 + -2 \cdot t_0\right)\right)\right) + \left(\left(1 + t_0\right) \cdot {wj}^{2} + \left(x + -2 \cdot \left(wj \cdot x\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(-wj\right) \cdot \mathsf{expm1}\left(-\mathsf{log1p}\left(wj\right)\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if wj < 3.10000000000000014e-5

    1. Initial program 13.0

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Simplified13.0

      \[\leadsto \color{blue}{wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}} \]
      Proof
      (-.f64 wj (/.f64 (-.f64 wj (/.f64 x (exp.f64 wj))) (+.f64 wj 1))): 0 points increase in error, 0 points decrease in error
      (-.f64 wj (Rewrite=> div-sub_binary64 (-.f64 (/.f64 wj (+.f64 wj 1)) (/.f64 (/.f64 x (exp.f64 wj)) (+.f64 wj 1))))): 0 points increase in error, 0 points decrease in error
      (-.f64 wj (-.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (/.f64 wj (+.f64 wj 1)) 1)) (/.f64 (/.f64 x (exp.f64 wj)) (+.f64 wj 1)))): 0 points increase in error, 0 points decrease in error
      (-.f64 wj (-.f64 (*.f64 (/.f64 wj (+.f64 wj 1)) (Rewrite<= *-inverses_binary64 (/.f64 (exp.f64 wj) (exp.f64 wj)))) (/.f64 (/.f64 x (exp.f64 wj)) (+.f64 wj 1)))): 1 points increase in error, 0 points decrease in error
      (-.f64 wj (-.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 wj (exp.f64 wj)) (*.f64 (+.f64 wj 1) (exp.f64 wj)))) (/.f64 (/.f64 x (exp.f64 wj)) (+.f64 wj 1)))): 2 points increase in error, 2 points decrease in error
      (-.f64 wj (-.f64 (/.f64 (*.f64 wj (exp.f64 wj)) (Rewrite<= distribute-rgt1-in_binary64 (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) (/.f64 (/.f64 x (exp.f64 wj)) (+.f64 wj 1)))): 1 points increase in error, 0 points decrease in error
      (-.f64 wj (-.f64 (/.f64 (*.f64 wj (exp.f64 wj)) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj)))) (Rewrite=> associate-/l/_binary64 (/.f64 x (*.f64 (+.f64 wj 1) (exp.f64 wj)))))): 1 points increase in error, 3 points decrease in error
      (-.f64 wj (-.f64 (/.f64 (*.f64 wj (exp.f64 wj)) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj)))) (/.f64 x (Rewrite<= distribute-rgt1-in_binary64 (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))))): 0 points increase in error, 1 points decrease in error
      (-.f64 wj (Rewrite<= div-sub_binary64 (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj)))))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in wj around 0 0.6

      \[\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.10000000000000014e-5 < wj

    1. Initial program 24.9

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Simplified25.1

      \[\leadsto \color{blue}{wj - \frac{wj \cdot e^{wj} - x}{\left(wj + 1\right) \cdot e^{wj}}} \]
      Proof
      (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (*.f64 (+.f64 wj 1) (exp.f64 wj)))): 0 points increase in error, 0 points decrease in error
      (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (Rewrite<= distribute-rgt1-in_binary64 (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj)))))): 1 points increase in error, 1 points decrease in error
    3. Applied egg-rr25.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(wj \cdot e^{wj} - x, -e^{\left(-wj\right) - \mathsf{log1p}\left(wj\right)}, wj\right)} \]
    4. Taylor expanded in wj around -inf 25.0

      \[\leadsto \color{blue}{-1 \cdot \left(wj \cdot \left(e^{wj} \cdot e^{-1 \cdot wj - \mathsf{log1p}\left(wj\right)} - 1\right)\right) + e^{-1 \cdot wj - \mathsf{log1p}\left(wj\right)} \cdot x} \]
    5. Simplified0.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(-wj, \mathsf{expm1}\left(wj - \left(wj + \mathsf{log1p}\left(wj\right)\right)\right), x \cdot e^{\left(-wj\right) - \mathsf{log1p}\left(wj\right)}\right)} \]
      Proof
      (fma.f64 (neg.f64 wj) (expm1.f64 (-.f64 wj (+.f64 wj (log1p.f64 wj)))) (*.f64 x (exp.f64 (-.f64 (neg.f64 wj) (log1p.f64 wj))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 wj)) (expm1.f64 (-.f64 wj (+.f64 wj (log1p.f64 wj)))) (*.f64 x (exp.f64 (-.f64 (neg.f64 wj) (log1p.f64 wj))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (expm1.f64 (Rewrite<= unsub-neg_binary64 (+.f64 wj (neg.f64 (+.f64 wj (log1p.f64 wj)))))) (*.f64 x (exp.f64 (-.f64 (neg.f64 wj) (log1p.f64 wj))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (expm1.f64 (+.f64 wj (Rewrite=> distribute-neg-in_binary64 (+.f64 (neg.f64 wj) (neg.f64 (log1p.f64 wj)))))) (*.f64 x (exp.f64 (-.f64 (neg.f64 wj) (log1p.f64 wj))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (expm1.f64 (+.f64 wj (+.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 wj)) (neg.f64 (log1p.f64 wj))))) (*.f64 x (exp.f64 (-.f64 (neg.f64 wj) (log1p.f64 wj))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (expm1.f64 (+.f64 wj (Rewrite<= sub-neg_binary64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj))))) (*.f64 x (exp.f64 (-.f64 (neg.f64 wj) (log1p.f64 wj))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 (+.f64 wj (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1)) (*.f64 x (exp.f64 (-.f64 (neg.f64 wj) (log1p.f64 wj))))): 38 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (Rewrite<= prod-exp_binary64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj))))) 1) (*.f64 x (exp.f64 (-.f64 (neg.f64 wj) (log1p.f64 wj))))): 5 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (-.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 wj)) (log1p.f64 wj))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (Rewrite<= associate--r+_binary64 (-.f64 0 (+.f64 wj (log1p.f64 wj))))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (+.f64 wj (log1p.f64 wj))))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 (log1p.f64 wj) wj)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (neg.f64 (+.f64 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 wj))) wj))))): 2 points increase in error, 1 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 (+.f64 (log.f64 (+.f64 1 wj)) wj)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (-.f64 0 (+.f64 (Rewrite=> log1p-def_binary64 (log1p.f64 wj)) wj))))): 1 points increase in error, 2 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (-.f64 0 (Rewrite=> +-commutative_binary64 (+.f64 wj (log1p.f64 wj))))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (Rewrite=> associate--r+_binary64 (-.f64 (-.f64 0 wj) (log1p.f64 wj)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (-.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 wj)) (log1p.f64 wj))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (*.f64 x (exp.f64 (-.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 wj)) (log1p.f64 wj))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1) (Rewrite<= *-commutative_binary64 (*.f64 (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj))) x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (*.f64 -1 wj) (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1)) (*.f64 (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj))) x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 -1 (*.f64 wj (-.f64 (*.f64 (exp.f64 wj) (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj)))) 1)))) (*.f64 (exp.f64 (-.f64 (*.f64 -1 wj) (log1p.f64 wj))) x)): 0 points increase in error, 0 points decrease in error
    6. Taylor expanded in x around 0 20.6

      \[\leadsto \color{blue}{-1 \cdot \left(wj \cdot \left(e^{-\log \left(1 + wj\right)} - 1\right)\right)} \]
    7. Simplified19.5

      \[\leadsto \color{blue}{\left(-wj\right) \cdot \mathsf{expm1}\left(-\mathsf{log1p}\left(wj\right)\right)} \]
      Proof
      (*.f64 (neg.f64 wj) (expm1.f64 (neg.f64 (log1p.f64 wj)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 wj)) (expm1.f64 (neg.f64 (log1p.f64 wj)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (*.f64 -1 wj) (expm1.f64 (neg.f64 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 wj)))))): 95 points increase in error, 46 points decrease in error
      (*.f64 (*.f64 -1 wj) (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 (neg.f64 (log.f64 (+.f64 1 wj)))) 1))): 6 points increase in error, 8 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 -1 (*.f64 wj (-.f64 (exp.f64 (neg.f64 (log.f64 (+.f64 1 wj)))) 1)))): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification1.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq 3.1 \cdot 10^{-5}:\\ \;\;\;\;{wj}^{3} \cdot \left(x \cdot -0.6666666666666666 + \left(x \cdot 3 + \left(-1 + -2 \cdot \left(x \cdot 4 + x \cdot -1.5\right)\right)\right)\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}:\\ \;\;\;\;\left(-wj\right) \cdot \mathsf{expm1}\left(-\mathsf{log1p}\left(wj\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.3
Cost32832
\[\mathsf{fma}\left(-wj, \mathsf{expm1}\left(wj - \left(wj + \mathsf{log1p}\left(wj\right)\right)\right), x \cdot e^{\left(-wj\right) - \mathsf{log1p}\left(wj\right)}\right) \]
Alternative 2
Error1.4
Cost19712
\[\mathsf{fma}\left(-wj, \mathsf{expm1}\left(wj - \left(wj + \mathsf{log1p}\left(wj\right)\right)\right), x\right) \]
Alternative 3
Error1.4
Cost13252
\[\begin{array}{l} \mathbf{if}\;wj \leq 3.1 \cdot 10^{-5}:\\ \;\;\;\;\left(x + -2 \cdot \left(wj \cdot x\right)\right) + {wj}^{2} \cdot \left(1 + x \cdot 2.5\right)\\ \mathbf{else}:\\ \;\;\;\;wj \cdot \left(-\mathsf{expm1}\left(-\mathsf{log1p}\left(wj\right)\right)\right)\\ \end{array} \]
Alternative 4
Error0.8
Cost8708
\[\begin{array}{l} \mathbf{if}\;wj \leq 1.65 \cdot 10^{-8}:\\ \;\;\;\;{wj}^{3} \cdot \left(x \cdot -0.6666666666666666 + \left(x \cdot 3 + \left(-1 + -2 \cdot \left(x \cdot 4 + x \cdot -1.5\right)\right)\right)\right) + \left(\left(x + -2 \cdot \left(wj \cdot x\right)\right) + wj \cdot wj\right)\\ \mathbf{else}:\\ \;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\ \end{array} \]
Alternative 5
Error1.4
Cost7556
\[\begin{array}{l} \mathbf{if}\;wj \leq 1.1 \cdot 10^{-5}:\\ \;\;\;\;\left(x + -2 \cdot \left(wj \cdot x\right)\right) + {wj}^{2} \cdot \left(1 + x \cdot 2.5\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{\mathsf{fma}\left(wj, wj, -1\right)} \cdot \left(wj + -1\right)\\ \end{array} \]
Alternative 6
Error1.4
Cost7236
\[\begin{array}{l} \mathbf{if}\;wj \leq 3.1 \cdot 10^{-5}:\\ \;\;\;\;wj \cdot wj + \frac{x - wj \cdot x}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{\mathsf{fma}\left(wj, wj, -1\right)} \cdot \left(wj + -1\right)\\ \end{array} \]
Alternative 7
Error1.0
Cost7236
\[\begin{array}{l} \mathbf{if}\;wj \leq 3.1 \cdot 10^{-9}:\\ \;\;\;\;wj \cdot wj + \frac{x - wj \cdot x}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\ \end{array} \]
Alternative 8
Error9.2
Cost972
\[\begin{array}{l} t_0 := \frac{x}{1 + wj \cdot 2}\\ \mathbf{if}\;wj \leq 1.35 \cdot 10^{-45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;wj \leq 1.35 \cdot 10^{-11}:\\ \;\;\;\;wj \cdot \left(wj - wj \cdot wj\right)\\ \mathbf{elif}\;wj \leq 2.85 \cdot 10^{-6}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;wj \cdot \left(1 + \frac{-1}{wj + 1}\right)\\ \end{array} \]
Alternative 9
Error9.1
Cost972
\[\begin{array}{l} t_0 := x \cdot \frac{1 - wj}{wj + 1}\\ \mathbf{if}\;wj \leq 3.8 \cdot 10^{-45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;wj \leq 3.2 \cdot 10^{-14}:\\ \;\;\;\;wj \cdot \left(wj - wj \cdot wj\right)\\ \mathbf{elif}\;wj \leq 4.8 \cdot 10^{-6}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;wj \cdot \left(1 + \frac{-1}{wj + 1}\right)\\ \end{array} \]
Alternative 10
Error9.2
Cost972
\[\begin{array}{l} \mathbf{if}\;wj \leq 2.3 \cdot 10^{-45}:\\ \;\;\;\;x \cdot \frac{1 - wj}{wj + 1}\\ \mathbf{elif}\;wj \leq 4.1 \cdot 10^{-11}:\\ \;\;\;\;wj \cdot \left(wj - wj \cdot wj\right)\\ \mathbf{elif}\;wj \leq 1.4 \cdot 10^{-5}:\\ \;\;\;\;\left(1 - wj\right) \cdot \frac{x}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;wj \cdot \left(1 + \frac{-1}{wj + 1}\right)\\ \end{array} \]
Alternative 11
Error1.4
Cost964
\[\begin{array}{l} \mathbf{if}\;wj \leq 2.3 \cdot 10^{-5}:\\ \;\;\;\;wj \cdot wj + \frac{x - wj \cdot x}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;wj \cdot \left(1 + \frac{-1}{wj + 1}\right)\\ \end{array} \]
Alternative 12
Error9.2
Cost844
\[\begin{array}{l} t_0 := x + -2 \cdot \left(wj \cdot x\right)\\ \mathbf{if}\;wj \leq 3.8 \cdot 10^{-45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;wj \leq 5.1 \cdot 10^{-11}:\\ \;\;\;\;wj \cdot \left(wj - wj \cdot wj\right)\\ \mathbf{elif}\;wj \leq 2.4 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{wj + 1}\\ \end{array} \]
Alternative 13
Error9.1
Cost844
\[\begin{array}{l} t_0 := \frac{x}{1 + wj \cdot 2}\\ \mathbf{if}\;wj \leq 6.8 \cdot 10^{-47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;wj \leq 2.85 \cdot 10^{-14}:\\ \;\;\;\;wj \cdot \left(wj - wj \cdot wj\right)\\ \mathbf{elif}\;wj \leq 3.1 \cdot 10^{-6}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{wj + 1}\\ \end{array} \]
Alternative 14
Error10.5
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -7.6 \cdot 10^{-268}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.45 \cdot 10^{-200}:\\ \;\;\;\;wj \cdot \left(wj - wj \cdot wj\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error10.2
Cost712
\[\begin{array}{l} t_0 := x + -2 \cdot \left(wj \cdot x\right)\\ \mathbf{if}\;x \leq -9.2 \cdot 10^{-268}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.45 \cdot 10^{-200}:\\ \;\;\;\;wj \cdot \left(wj - wj \cdot wj\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 16
Error8.0
Cost576
\[x + \left(wj - \frac{wj}{wj + 1}\right) \]
Alternative 17
Error10.6
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -8.4 \cdot 10^{-269}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.45 \cdot 10^{-200}:\\ \;\;\;\;wj \cdot wj\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 18
Error61.2
Cost64
\[wj \]
Alternative 19
Error9.6
Cost64
\[x \]

Error

Reproduce

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