
(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:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (wj x)
:precision binary64
(let* ((t_0 (* wj (exp wj))))
(if (<= (+ wj (/ (- x t_0) (+ (exp wj) t_0))) 2.2e-13)
(- (fma wj wj (+ x (* x (* wj -2.0)))) (pow wj 3.0))
(+ wj (/ (- (/ x (exp wj)) wj) (+ wj 1.0))))))
double code(double wj, double x) {
double t_0 = wj * exp(wj);
double tmp;
if ((wj + ((x - t_0) / (exp(wj) + t_0))) <= 2.2e-13) {
tmp = fma(wj, wj, (x + (x * (wj * -2.0)))) - pow(wj, 3.0);
} else {
tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0));
}
return tmp;
}
function code(wj, x) t_0 = Float64(wj * exp(wj)) tmp = 0.0 if (Float64(wj + Float64(Float64(x - t_0) / Float64(exp(wj) + t_0))) <= 2.2e-13) tmp = Float64(fma(wj, wj, Float64(x + Float64(x * Float64(wj * -2.0)))) - (wj ^ 3.0)); else tmp = Float64(wj + Float64(Float64(Float64(x / exp(wj)) - wj) / Float64(wj + 1.0))); end return tmp end
code[wj_, x_] := Block[{t$95$0 = N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(wj + N[(N[(x - t$95$0), $MachinePrecision] / N[(N[Exp[wj], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.2e-13], N[(N[(wj * wj + N[(x + N[(x * N[(wj * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Power[wj, 3.0], $MachinePrecision]), $MachinePrecision], N[(wj + N[(N[(N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := wj \cdot e^{wj}\\
\mathbf{if}\;wj + \frac{x - t_0}{e^{wj} + t_0} \leq 2.2 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, x + x \cdot \left(wj \cdot -2\right)\right) - {wj}^{3}\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\
\end{array}
\end{array}
if (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) < 2.19999999999999997e-13Initial program 78.1%
div-sub78.1%
associate-/l*78.1%
distribute-rgt1-in78.1%
associate-/l*78.1%
*-inverses78.1%
/-rgt-identity78.1%
distribute-rgt1-in78.6%
associate-/l/78.6%
div-sub78.6%
Simplified78.6%
Taylor expanded in wj around 0 98.8%
associate-+r+98.8%
+-commutative98.8%
fma-def98.8%
*-commutative98.8%
+-commutative98.8%
mul-1-neg98.8%
unsub-neg98.8%
Simplified98.8%
Taylor expanded in x around 0 98.9%
Taylor expanded in x around 0 99.4%
+-commutative99.4%
unpow299.4%
fma-def99.4%
distribute-lft-in99.4%
*-rgt-identity99.4%
+-commutative99.4%
*-commutative99.4%
fma-def99.4%
unpow299.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in wj around 0 99.4%
*-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
*-commutative99.4%
Simplified99.4%
if 2.19999999999999997e-13 < (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) Initial program 95.2%
div-sub95.2%
associate-/l*95.2%
distribute-rgt1-in95.2%
associate-/l*95.2%
*-inverses96.7%
/-rgt-identity96.7%
distribute-rgt1-in99.7%
associate-/l/99.7%
div-sub99.7%
Simplified99.7%
Final simplification99.5%
(FPCore (wj x) :precision binary64 (+ (fma -2.0 (* wj x) x) (- (* wj wj) (pow wj 3.0))))
double code(double wj, double x) {
return fma(-2.0, (wj * x), x) + ((wj * wj) - pow(wj, 3.0));
}
function code(wj, x) return Float64(fma(-2.0, Float64(wj * x), x) + Float64(Float64(wj * wj) - (wj ^ 3.0))) end
code[wj_, x_] := N[(N[(-2.0 * N[(wj * x), $MachinePrecision] + x), $MachinePrecision] + N[(N[(wj * wj), $MachinePrecision] - N[Power[wj, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-2, wj \cdot x, x\right) + \left(wj \cdot wj - {wj}^{3}\right)
\end{array}
Initial program 82.6%
div-sub82.6%
associate-/l*82.6%
distribute-rgt1-in82.6%
associate-/l*82.6%
*-inverses83.0%
/-rgt-identity83.0%
distribute-rgt1-in84.1%
associate-/l/84.1%
div-sub84.1%
Simplified84.1%
Taylor expanded in wj around 0 97.5%
associate-+r+97.5%
+-commutative97.5%
fma-def97.5%
*-commutative97.5%
+-commutative97.5%
mul-1-neg97.5%
unsub-neg97.5%
Simplified97.5%
Taylor expanded in x around 0 97.6%
Taylor expanded in x around 0 97.9%
unpow297.9%
Simplified97.9%
Final simplification97.9%
(FPCore (wj x) :precision binary64 (fma wj wj (fma x (* wj (+ -2.0 (* wj 2.5))) x)))
double code(double wj, double x) {
return fma(wj, wj, fma(x, (wj * (-2.0 + (wj * 2.5))), x));
}
function code(wj, x) return fma(wj, wj, fma(x, Float64(wj * Float64(-2.0 + Float64(wj * 2.5))), x)) end
code[wj_, x_] := N[(wj * wj + N[(x * N[(wj * N[(-2.0 + N[(wj * 2.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(wj, wj, \mathsf{fma}\left(x, wj \cdot \left(-2 + wj \cdot 2.5\right), x\right)\right)
\end{array}
Initial program 82.6%
div-sub82.6%
associate-/l*82.6%
distribute-rgt1-in82.6%
associate-/l*82.6%
*-inverses83.0%
/-rgt-identity83.0%
distribute-rgt1-in84.1%
associate-/l/84.1%
div-sub84.1%
Simplified84.1%
Taylor expanded in wj around 0 97.5%
associate-+r+97.5%
+-commutative97.5%
fma-def97.5%
*-commutative97.5%
+-commutative97.5%
mul-1-neg97.5%
unsub-neg97.5%
Simplified97.5%
Taylor expanded in x around 0 97.6%
Taylor expanded in x around 0 97.9%
+-commutative97.9%
unpow297.9%
fma-def97.9%
distribute-lft-in97.9%
*-rgt-identity97.9%
+-commutative97.9%
*-commutative97.9%
fma-def97.9%
unpow297.9%
*-commutative97.9%
Simplified97.9%
Taylor expanded in wj around 0 97.2%
+-commutative97.2%
Simplified97.5%
Final simplification97.5%
(FPCore (wj x) :precision binary64 (if (<= wj 7.2e-24) x (- (* wj wj) (* wj (* wj wj)))))
double code(double wj, double x) {
double tmp;
if (wj <= 7.2e-24) {
tmp = x;
} else {
tmp = (wj * wj) - (wj * (wj * wj));
}
return tmp;
}
real(8) function code(wj, x)
real(8), intent (in) :: wj
real(8), intent (in) :: x
real(8) :: tmp
if (wj <= 7.2d-24) then
tmp = x
else
tmp = (wj * wj) - (wj * (wj * wj))
end if
code = tmp
end function
public static double code(double wj, double x) {
double tmp;
if (wj <= 7.2e-24) {
tmp = x;
} else {
tmp = (wj * wj) - (wj * (wj * wj));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= 7.2e-24: tmp = x else: tmp = (wj * wj) - (wj * (wj * wj)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= 7.2e-24) tmp = x; else tmp = Float64(Float64(wj * wj) - Float64(wj * Float64(wj * wj))); end return tmp end
function tmp_2 = code(wj, x) tmp = 0.0; if (wj <= 7.2e-24) tmp = x; else tmp = (wj * wj) - (wj * (wj * wj)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, 7.2e-24], x, N[(N[(wj * wj), $MachinePrecision] - N[(wj * N[(wj * wj), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq 7.2 \cdot 10^{-24}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;wj \cdot wj - wj \cdot \left(wj \cdot wj\right)\\
\end{array}
\end{array}
if wj < 7.2000000000000002e-24Initial program 84.1%
div-sub84.1%
associate-/l*84.1%
distribute-rgt1-in84.1%
associate-/l*84.1%
*-inverses84.1%
/-rgt-identity84.1%
distribute-rgt1-in85.3%
associate-/l/85.3%
div-sub85.3%
Simplified85.3%
Taylor expanded in wj around 0 90.7%
if 7.2000000000000002e-24 < wj Initial program 45.3%
div-sub45.3%
associate-/l*45.2%
distribute-rgt1-in45.2%
associate-/l*45.2%
*-inverses55.2%
/-rgt-identity55.2%
distribute-rgt1-in55.2%
associate-/l/55.4%
div-sub55.4%
Simplified55.4%
Taylor expanded in x around 0 45.3%
+-commutative45.3%
Simplified45.3%
Taylor expanded in wj around 0 58.6%
+-commutative58.6%
mul-1-neg58.6%
unsub-neg58.6%
unpow258.6%
Simplified58.6%
unpow358.6%
cancel-sign-sub-inv58.6%
Applied egg-rr58.6%
Final simplification89.4%
(FPCore (wj x) :precision binary64 (+ x (+ (* x (* wj -2.0)) (* wj wj))))
double code(double wj, double x) {
return x + ((x * (wj * -2.0)) + (wj * wj));
}
real(8) function code(wj, x)
real(8), intent (in) :: wj
real(8), intent (in) :: x
code = x + ((x * (wj * (-2.0d0))) + (wj * wj))
end function
public static double code(double wj, double x) {
return x + ((x * (wj * -2.0)) + (wj * wj));
}
def code(wj, x): return x + ((x * (wj * -2.0)) + (wj * wj))
function code(wj, x) return Float64(x + Float64(Float64(x * Float64(wj * -2.0)) + Float64(wj * wj))) end
function tmp = code(wj, x) tmp = x + ((x * (wj * -2.0)) + (wj * wj)); end
code[wj_, x_] := N[(x + N[(N[(x * N[(wj * -2.0), $MachinePrecision]), $MachinePrecision] + N[(wj * wj), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x \cdot \left(wj \cdot -2\right) + wj \cdot wj\right)
\end{array}
Initial program 82.6%
div-sub82.6%
associate-/l*82.6%
distribute-rgt1-in82.6%
associate-/l*82.6%
*-inverses83.0%
/-rgt-identity83.0%
distribute-rgt1-in84.1%
associate-/l/84.1%
div-sub84.1%
Simplified84.1%
Taylor expanded in wj around 0 97.2%
+-commutative97.2%
fma-def97.2%
unpow297.2%
sub-neg97.2%
distribute-rgt-out97.2%
distribute-rgt-neg-in97.2%
metadata-eval97.2%
metadata-eval97.2%
associate-*r*97.2%
*-commutative97.2%
Simplified97.2%
fma-udef97.2%
associate-*l*97.2%
*-commutative97.2%
Applied egg-rr97.2%
Taylor expanded in x around 0 97.5%
Final simplification97.5%
(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}
Initial program 82.6%
div-sub82.6%
associate-/l*82.6%
distribute-rgt1-in82.6%
associate-/l*82.6%
*-inverses83.0%
/-rgt-identity83.0%
distribute-rgt1-in84.1%
associate-/l/84.1%
div-sub84.1%
Simplified84.1%
Taylor expanded in wj around 0 87.7%
*-commutative87.7%
Simplified87.7%
Final simplification87.7%
(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}
Initial program 82.6%
div-sub82.6%
associate-/l*82.6%
distribute-rgt1-in82.6%
associate-/l*82.6%
*-inverses83.0%
/-rgt-identity83.0%
distribute-rgt1-in84.1%
associate-/l/84.1%
div-sub84.1%
Simplified84.1%
Taylor expanded in wj around inf 4.3%
Final simplification4.3%
(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}
Initial program 82.6%
div-sub82.6%
associate-/l*82.6%
distribute-rgt1-in82.6%
associate-/l*82.6%
*-inverses83.0%
/-rgt-identity83.0%
distribute-rgt1-in84.1%
associate-/l/84.1%
div-sub84.1%
Simplified84.1%
Taylor expanded in wj around 0 87.6%
Final simplification87.6%
(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}
herbie shell --seed 2023275
(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))))))