?

Average Error: 79.8% → 99.5%
Time: 32.6s
Precision: binary64
Cost: 7624.00

?

\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
\[\begin{array}{l} t_0 := \frac{x}{e^{wj}}\\ \mathbf{if}\;wj \leq -4.6 \cdot 10^{-9}:\\ \;\;\;\;wj - \frac{wj - t_0}{wj + 1}\\ \mathbf{elif}\;wj \leq 7.4 \cdot 10^{-9}:\\ \;\;\;\;wj \cdot wj + \frac{x}{\frac{wj + 1}{1 - wj}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{wj + 1} + \left(wj - \frac{wj}{wj + 1}\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 (exp wj))))
   (if (<= wj -4.6e-9)
     (- wj (/ (- wj t_0) (+ wj 1.0)))
     (if (<= wj 7.4e-9)
       (+ (* wj wj) (/ x (/ (+ wj 1.0) (- 1.0 wj))))
       (+ (/ t_0 (+ wj 1.0)) (- wj (/ wj (+ wj 1.0))))))))
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 / exp(wj);
	double tmp;
	if (wj <= -4.6e-9) {
		tmp = wj - ((wj - t_0) / (wj + 1.0));
	} else if (wj <= 7.4e-9) {
		tmp = (wj * wj) + (x / ((wj + 1.0) / (1.0 - wj)));
	} else {
		tmp = (t_0 / (wj + 1.0)) + (wj - (wj / (wj + 1.0)));
	}
	return tmp;
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    code = wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))))
end function
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 = x / exp(wj)
    if (wj <= (-4.6d-9)) then
        tmp = wj - ((wj - t_0) / (wj + 1.0d0))
    else if (wj <= 7.4d-9) then
        tmp = (wj * wj) + (x / ((wj + 1.0d0) / (1.0d0 - wj)))
    else
        tmp = (t_0 / (wj + 1.0d0)) + (wj - (wj / (wj + 1.0d0)))
    end if
    code = tmp
end function
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 / Math.exp(wj);
	double tmp;
	if (wj <= -4.6e-9) {
		tmp = wj - ((wj - t_0) / (wj + 1.0));
	} else if (wj <= 7.4e-9) {
		tmp = (wj * wj) + (x / ((wj + 1.0) / (1.0 - wj)));
	} else {
		tmp = (t_0 / (wj + 1.0)) + (wj - (wj / (wj + 1.0)));
	}
	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 / math.exp(wj)
	tmp = 0
	if wj <= -4.6e-9:
		tmp = wj - ((wj - t_0) / (wj + 1.0))
	elif wj <= 7.4e-9:
		tmp = (wj * wj) + (x / ((wj + 1.0) / (1.0 - wj)))
	else:
		tmp = (t_0 / (wj + 1.0)) + (wj - (wj / (wj + 1.0)))
	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(x / exp(wj))
	tmp = 0.0
	if (wj <= -4.6e-9)
		tmp = Float64(wj - Float64(Float64(wj - t_0) / Float64(wj + 1.0)));
	elseif (wj <= 7.4e-9)
		tmp = Float64(Float64(wj * wj) + Float64(x / Float64(Float64(wj + 1.0) / Float64(1.0 - wj))));
	else
		tmp = Float64(Float64(t_0 / Float64(wj + 1.0)) + Float64(wj - Float64(wj / Float64(wj + 1.0))));
	end
	return tmp
end
function tmp = code(wj, x)
	tmp = wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))));
end
function tmp_2 = code(wj, x)
	t_0 = x / exp(wj);
	tmp = 0.0;
	if (wj <= -4.6e-9)
		tmp = wj - ((wj - t_0) / (wj + 1.0));
	elseif (wj <= 7.4e-9)
		tmp = (wj * wj) + (x / ((wj + 1.0) / (1.0 - wj)));
	else
		tmp = (t_0 / (wj + 1.0)) + (wj - (wj / (wj + 1.0)));
	end
	tmp_2 = 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[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[wj, -4.6e-9], N[(wj - N[(N[(wj - t$95$0), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[wj, 7.4e-9], N[(N[(wj * wj), $MachinePrecision] + N[(x / N[(N[(wj + 1.0), $MachinePrecision] / N[(1.0 - wj), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision] + N[(wj - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
t_0 := \frac{x}{e^{wj}}\\
\mathbf{if}\;wj \leq -4.6 \cdot 10^{-9}:\\
\;\;\;\;wj - \frac{wj - t_0}{wj + 1}\\

\mathbf{elif}\;wj \leq 7.4 \cdot 10^{-9}:\\
\;\;\;\;wj \cdot wj + \frac{x}{\frac{wj + 1}{1 - wj}}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original79.8%
Target80.7%
Herbie99.5%
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right) \]

Derivation?

  1. Split input into 3 regimes
  2. if wj < -4.5999999999999998e-9

    1. Initial program 90.6

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Simplified90.7

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

      [Start]90.6

      \[ wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]

      sub-neg [=>]90.6

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

      neg-mul-1 [=>]90.6

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

      *-commutative [=>]90.6

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

      *-commutative [<=]90.6

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

      neg-mul-1 [<=]90.6

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

      neg-sub0 [=>]90.6

      \[ wj + \color{blue}{\left(0 - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]

      div-sub [=>]90.6

      \[ wj + \left(0 - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]

      associate--r- [=>]90.6

      \[ wj + \color{blue}{\left(\left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)} \]

      +-commutative [=>]90.6

      \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} + \left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]

      sub0-neg [=>]90.6

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

      sub-neg [<=]90.6

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

    if -4.5999999999999998e-9 < wj < 7.4e-9

    1. Initial program 80.1

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

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

      [Start]80.1

      \[ wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]

      sub-neg [=>]80.1

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

      neg-mul-1 [=>]80.1

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

      *-commutative [=>]80.1

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

      *-commutative [<=]80.1

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

      neg-mul-1 [<=]80.1

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

      neg-sub0 [=>]80.1

      \[ wj + \color{blue}{\left(0 - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]

      div-sub [=>]80.1

      \[ wj + \left(0 - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]

      associate--r- [=>]80.1

      \[ wj + \color{blue}{\left(\left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)} \]

      +-commutative [=>]80.1

      \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} + \left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]

      sub0-neg [=>]80.1

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

      sub-neg [<=]80.1

      \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
    3. Taylor expanded in wj around 0 80.1

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

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

      [Start]80.1

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

      +-commutative [=>]80.1

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

      mul-1-neg [=>]80.1

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

      unsub-neg [=>]80.1

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

      *-commutative [<=]80.1

      \[ wj + \frac{\left(x - \color{blue}{x \cdot wj}\right) - wj}{wj + 1} \]
    5. Applied egg-rr89.4

      \[\leadsto \color{blue}{\frac{x}{\frac{wj + 1}{1 - wj}} - \left(\frac{wj}{wj + 1} - wj\right)} \]
    6. Taylor expanded in wj around 0 99.7

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

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

      [Start]99.7

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

      unpow2 [=>]99.7

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

      mul-1-neg [=>]99.7

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

      distribute-rgt-neg-in [=>]99.7

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

    if 7.4e-9 < wj

    1. Initial program 63.5

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
    2. Simplified95.5

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

      [Start]63.5

      \[ wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]

      sub-neg [=>]63.5

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

      neg-mul-1 [=>]63.5

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

      *-commutative [=>]63.5

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

      *-commutative [<=]63.5

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

      neg-mul-1 [<=]63.5

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

      neg-sub0 [=>]63.5

      \[ wj + \color{blue}{\left(0 - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]

      div-sub [=>]63.5

      \[ wj + \left(0 - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]

      associate--r- [=>]63.5

      \[ wj + \color{blue}{\left(\left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)} \]

      +-commutative [=>]63.5

      \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} + \left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]

      sub0-neg [=>]63.5

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

      sub-neg [<=]63.5

      \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
    3. Applied egg-rr95.5

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

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

Alternatives

Alternative 1
Error99.1%
Cost33860.00
\[\begin{array}{l} t_0 := wj \cdot e^{wj}\\ \mathbf{if}\;wj + \frac{x - t_0}{e^{wj} + t_0} \leq 10^{-12}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(-2, wj, 1\right) + \left(wj \cdot wj\right) \cdot \left(\mathsf{fma}\left(x, 2.5, 1\right) - wj\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{x}{e^{wj}} - wj}{1 - wj \cdot wj}, 1 - wj, wj\right)\\ \end{array} \]
Alternative 2
Error99.0%
Cost13892.00
\[\begin{array}{l} \mathbf{if}\;wj \leq 2.3 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(-2, wj, 1\right) + \left(wj \cdot wj\right) \cdot \left(\mathsf{fma}\left(x, 2.5, 1\right) - wj\right)\\ \mathbf{else}:\\ \;\;\;\;wj + \frac{1 - wj}{\frac{1 - wj \cdot wj}{\frac{x}{e^{wj}} - wj}}\\ \end{array} \]
Alternative 3
Error99.0%
Cost7620.00
\[\begin{array}{l} \mathbf{if}\;wj \leq 8.8 \cdot 10^{-7}:\\ \;\;\;\;\frac{x}{\frac{wj + 1}{1 - wj}} + \left(wj \cdot wj - {wj}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;wj + \frac{1 - wj}{\frac{1 - wj \cdot wj}{\frac{x}{e^{wj}} - wj}}\\ \end{array} \]
Alternative 4
Error99.0%
Cost7556.00
\[\begin{array}{l} \mathbf{if}\;wj \leq 8.8 \cdot 10^{-7}:\\ \;\;\;\;\frac{x}{\frac{wj + 1}{1 - wj}} + \left(wj \cdot wj - {wj}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\ \end{array} \]
Alternative 5
Error99.5%
Cost7369.00
\[\begin{array}{l} \mathbf{if}\;wj \leq -4.5 \cdot 10^{-9} \lor \neg \left(wj \leq 7.4 \cdot 10^{-9}\right):\\ \;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;wj \cdot wj + \frac{x}{\frac{wj + 1}{1 - wj}}\\ \end{array} \]
Alternative 6
Error97.7%
Cost964.00
\[\begin{array}{l} \mathbf{if}\;wj \leq 0.00325:\\ \;\;\;\;wj \cdot wj + \frac{x}{\frac{wj + 1}{1 - wj}}\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{wj + 1}\\ \end{array} \]
Alternative 7
Error87.5%
Cost832.00
\[\frac{x}{wj + 1} + \left(wj - \frac{wj}{wj + 1}\right) \]
Alternative 8
Error86.9%
Cost580.00
\[\begin{array}{l} \mathbf{if}\;wj \leq 3.4 \cdot 10^{-5}:\\ \;\;\;\;x - \left(wj \cdot x\right) \cdot 2\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{wj}{wj + 1}\\ \end{array} \]
Alternative 9
Error87.4%
Cost576.00
\[x + \left(wj - \frac{wj}{wj + 1}\right) \]
Alternative 10
Error85.6%
Cost448.00
\[x - \left(wj \cdot x\right) \cdot 2 \]
Alternative 11
Error4.4%
Cost64.00
\[wj \]
Alternative 12
Error85.1%
Cost64.00
\[x \]

Error

Reproduce?

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