
(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 7 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 (/ (- t_0 x) (+ (exp wj) t_0))) 5e-26)
(- (+ (* wj wj) (+ x (* -2.0 (* wj x)))) (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 - ((t_0 - x) / (exp(wj) + t_0))) <= 5e-26) {
tmp = ((wj * wj) + (x + (-2.0 * (wj * x)))) - pow(wj, 3.0);
} else {
tmp = wj + (((x / exp(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) :: t_0
real(8) :: tmp
t_0 = wj * exp(wj)
if ((wj - ((t_0 - x) / (exp(wj) + t_0))) <= 5d-26) then
tmp = ((wj * wj) + (x + ((-2.0d0) * (wj * x)))) - (wj ** 3.0d0)
else
tmp = wj + (((x / exp(wj)) - 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 tmp;
if ((wj - ((t_0 - x) / (Math.exp(wj) + t_0))) <= 5e-26) {
tmp = ((wj * wj) + (x + (-2.0 * (wj * x)))) - Math.pow(wj, 3.0);
} else {
tmp = wj + (((x / Math.exp(wj)) - wj) / (wj + 1.0));
}
return tmp;
}
def code(wj, x): t_0 = wj * math.exp(wj) tmp = 0 if (wj - ((t_0 - x) / (math.exp(wj) + t_0))) <= 5e-26: tmp = ((wj * wj) + (x + (-2.0 * (wj * x)))) - math.pow(wj, 3.0) else: tmp = wj + (((x / math.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(t_0 - x) / Float64(exp(wj) + t_0))) <= 5e-26) tmp = Float64(Float64(Float64(wj * wj) + Float64(x + Float64(-2.0 * Float64(wj * x)))) - (wj ^ 3.0)); else tmp = Float64(wj + Float64(Float64(Float64(x / exp(wj)) - wj) / Float64(wj + 1.0))); end return tmp end
function tmp_2 = code(wj, x) t_0 = wj * exp(wj); tmp = 0.0; if ((wj - ((t_0 - x) / (exp(wj) + t_0))) <= 5e-26) tmp = ((wj * wj) + (x + (-2.0 * (wj * x)))) - (wj ^ 3.0); else tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0)); end tmp_2 = tmp; end
code[wj_, x_] := Block[{t$95$0 = N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(wj - N[(N[(t$95$0 - x), $MachinePrecision] / N[(N[Exp[wj], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-26], N[(N[(N[(wj * wj), $MachinePrecision] + N[(x + N[(-2.0 * N[(wj * x), $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{t_0 - x}{e^{wj} + t_0} \leq 5 \cdot 10^{-26}:\\
\;\;\;\;\left(wj \cdot wj + \left(x + -2 \cdot \left(wj \cdot x\right)\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))))) < 5.00000000000000019e-26Initial program 72.0%
sub-neg72.0%
div-sub72.0%
sub-neg72.0%
+-commutative72.0%
distribute-neg-in72.0%
remove-double-neg72.0%
sub-neg72.0%
div-sub72.0%
distribute-rgt1-in72.0%
associate-/l/72.0%
Simplified72.0%
Taylor expanded in wj around 0 99.4%
Taylor expanded in x around 0 99.4%
unpow299.4%
Simplified99.4%
Taylor expanded in x around 0 99.4%
if 5.00000000000000019e-26 < (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) Initial program 96.4%
sub-neg96.4%
div-sub96.4%
sub-neg96.4%
+-commutative96.4%
distribute-neg-in96.4%
remove-double-neg96.4%
sub-neg96.4%
div-sub96.4%
distribute-rgt1-in97.6%
associate-/l/97.6%
Simplified100.0%
Final simplification99.6%
(FPCore (wj x) :precision binary64 (+ (+ x (* -2.0 (* wj x))) (pow wj 2.0)))
double code(double wj, double x) {
return (x + (-2.0 * (wj * x))) + pow(wj, 2.0);
}
real(8) function code(wj, x)
real(8), intent (in) :: wj
real(8), intent (in) :: x
code = (x + ((-2.0d0) * (wj * x))) + (wj ** 2.0d0)
end function
public static double code(double wj, double x) {
return (x + (-2.0 * (wj * x))) + Math.pow(wj, 2.0);
}
def code(wj, x): return (x + (-2.0 * (wj * x))) + math.pow(wj, 2.0)
function code(wj, x) return Float64(Float64(x + Float64(-2.0 * Float64(wj * x))) + (wj ^ 2.0)) end
function tmp = code(wj, x) tmp = (x + (-2.0 * (wj * x))) + (wj ^ 2.0); end
code[wj_, x_] := N[(N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[wj, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + -2 \cdot \left(wj \cdot x\right)\right) + {wj}^{2}
\end{array}
Initial program 80.1%
sub-neg80.1%
div-sub80.1%
sub-neg80.1%
+-commutative80.1%
distribute-neg-in80.1%
remove-double-neg80.1%
sub-neg80.1%
div-sub80.1%
distribute-rgt1-in80.5%
associate-/l/80.5%
Simplified81.3%
Taylor expanded in wj around 0 97.1%
Taylor expanded in x around 0 97.1%
unpow297.1%
Simplified97.1%
Taylor expanded in x around 0 97.1%
Taylor expanded in wj around 0 97.1%
Final simplification97.1%
(FPCore (wj x) :precision binary64 (if (<= wj 1.1e-16) (/ (/ x (+ wj 1.0)) (exp wj)) (- wj (/ wj (+ wj 1.0)))))
double code(double wj, double x) {
double tmp;
if (wj <= 1.1e-16) {
tmp = (x / (wj + 1.0)) / exp(wj);
} 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.1d-16) then
tmp = (x / (wj + 1.0d0)) / exp(wj)
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.1e-16) {
tmp = (x / (wj + 1.0)) / Math.exp(wj);
} else {
tmp = wj - (wj / (wj + 1.0));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= 1.1e-16: tmp = (x / (wj + 1.0)) / math.exp(wj) else: tmp = wj - (wj / (wj + 1.0)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= 1.1e-16) tmp = Float64(Float64(x / Float64(wj + 1.0)) / exp(wj)); 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.1e-16) tmp = (x / (wj + 1.0)) / exp(wj); else tmp = wj - (wj / (wj + 1.0)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, 1.1e-16], N[(N[(x / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision] / N[Exp[wj], $MachinePrecision]), $MachinePrecision], N[(wj - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq 1.1 \cdot 10^{-16}:\\
\;\;\;\;\frac{\frac{x}{wj + 1}}{e^{wj}}\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\
\end{array}
\end{array}
if wj < 1.1e-16Initial program 81.0%
sub-neg81.0%
div-sub81.0%
sub-neg81.0%
+-commutative81.0%
distribute-neg-in81.0%
remove-double-neg81.0%
sub-neg81.0%
div-sub81.0%
distribute-rgt1-in81.4%
associate-/l/81.4%
Simplified81.4%
Taylor expanded in x around inf 89.2%
associate-/r*89.2%
+-commutative89.2%
Simplified89.2%
if 1.1e-16 < wj Initial program 43.1%
sub-neg43.1%
div-sub43.1%
sub-neg43.1%
+-commutative43.1%
distribute-neg-in43.1%
remove-double-neg43.1%
sub-neg43.1%
div-sub43.1%
distribute-rgt1-in43.1%
associate-/l/43.1%
Simplified76.5%
Taylor expanded in x around 0 76.5%
+-commutative76.5%
Simplified76.5%
Final simplification88.9%
(FPCore (wj x) :precision binary64 (if (<= wj 1.1e-16) (/ (* x (- 1.0 wj)) (+ wj 1.0)) (- wj (/ wj (+ wj 1.0)))))
double code(double wj, double x) {
double tmp;
if (wj <= 1.1e-16) {
tmp = (x * (1.0 - wj)) / (wj + 1.0);
} 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.1d-16) then
tmp = (x * (1.0d0 - wj)) / (wj + 1.0d0)
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.1e-16) {
tmp = (x * (1.0 - wj)) / (wj + 1.0);
} else {
tmp = wj - (wj / (wj + 1.0));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= 1.1e-16: tmp = (x * (1.0 - wj)) / (wj + 1.0) else: tmp = wj - (wj / (wj + 1.0)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= 1.1e-16) tmp = Float64(Float64(x * Float64(1.0 - wj)) / Float64(wj + 1.0)); 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.1e-16) tmp = (x * (1.0 - wj)) / (wj + 1.0); else tmp = wj - (wj / (wj + 1.0)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, 1.1e-16], N[(N[(x * N[(1.0 - wj), $MachinePrecision]), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision], N[(wj - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq 1.1 \cdot 10^{-16}:\\
\;\;\;\;\frac{x \cdot \left(1 - wj\right)}{wj + 1}\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\
\end{array}
\end{array}
if wj < 1.1e-16Initial program 81.0%
sub-neg81.0%
div-sub81.0%
sub-neg81.0%
+-commutative81.0%
distribute-neg-in81.0%
remove-double-neg81.0%
sub-neg81.0%
div-sub81.0%
distribute-rgt1-in81.4%
associate-/l/81.4%
Simplified81.4%
Taylor expanded in wj around 0 80.6%
+-commutative80.6%
mul-1-neg80.6%
unsub-neg80.6%
*-lft-identity80.6%
distribute-rgt-out--80.6%
Simplified80.6%
Taylor expanded in x around -inf 88.4%
if 1.1e-16 < wj Initial program 43.1%
sub-neg43.1%
div-sub43.1%
sub-neg43.1%
+-commutative43.1%
distribute-neg-in43.1%
remove-double-neg43.1%
sub-neg43.1%
div-sub43.1%
distribute-rgt1-in43.1%
associate-/l/43.1%
Simplified76.5%
Taylor expanded in x around 0 76.5%
+-commutative76.5%
Simplified76.5%
Final simplification88.1%
(FPCore (wj x) :precision binary64 (if (<= wj 1.1e-16) x (- wj (/ wj (+ wj 1.0)))))
double code(double wj, double x) {
double tmp;
if (wj <= 1.1e-16) {
tmp = 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.1d-16) then
tmp = 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.1e-16) {
tmp = x;
} else {
tmp = wj - (wj / (wj + 1.0));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= 1.1e-16: tmp = x else: tmp = wj - (wj / (wj + 1.0)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= 1.1e-16) tmp = 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.1e-16) tmp = x; else tmp = wj - (wj / (wj + 1.0)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, 1.1e-16], x, N[(wj - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq 1.1 \cdot 10^{-16}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\
\end{array}
\end{array}
if wj < 1.1e-16Initial program 81.0%
sub-neg81.0%
div-sub81.0%
sub-neg81.0%
+-commutative81.0%
distribute-neg-in81.0%
remove-double-neg81.0%
sub-neg81.0%
div-sub81.0%
distribute-rgt1-in81.4%
associate-/l/81.4%
Simplified81.4%
Taylor expanded in wj around 0 88.4%
if 1.1e-16 < wj Initial program 43.1%
sub-neg43.1%
div-sub43.1%
sub-neg43.1%
+-commutative43.1%
distribute-neg-in43.1%
remove-double-neg43.1%
sub-neg43.1%
div-sub43.1%
distribute-rgt1-in43.1%
associate-/l/43.1%
Simplified76.5%
Taylor expanded in x around 0 76.5%
+-commutative76.5%
Simplified76.5%
Final simplification88.1%
(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 80.1%
sub-neg80.1%
div-sub80.1%
sub-neg80.1%
+-commutative80.1%
distribute-neg-in80.1%
remove-double-neg80.1%
sub-neg80.1%
div-sub80.1%
distribute-rgt1-in80.5%
associate-/l/80.5%
Simplified81.3%
Taylor expanded in wj around inf 4.5%
Final simplification4.5%
(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 80.1%
sub-neg80.1%
div-sub80.1%
sub-neg80.1%
+-commutative80.1%
distribute-neg-in80.1%
remove-double-neg80.1%
sub-neg80.1%
div-sub80.1%
distribute-rgt1-in80.5%
associate-/l/80.5%
Simplified81.3%
Taylor expanded in wj around 0 86.4%
Final simplification86.4%
(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 2023242
(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))))))