
(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 12 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 (if (or (<= wj -5.5e-9) (not (<= wj 1.95e-10))) (- wj (/ (- wj (/ x (exp wj))) (+ wj 1.0))) (+ x (+ (* -2.0 (* wj x)) (* wj wj)))))
double code(double wj, double x) {
double tmp;
if ((wj <= -5.5e-9) || !(wj <= 1.95e-10)) {
tmp = wj - ((wj - (x / exp(wj))) / (wj + 1.0));
} else {
tmp = x + ((-2.0 * (wj * x)) + (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 <= (-5.5d-9)) .or. (.not. (wj <= 1.95d-10))) then
tmp = wj - ((wj - (x / exp(wj))) / (wj + 1.0d0))
else
tmp = x + (((-2.0d0) * (wj * x)) + (wj * wj))
end if
code = tmp
end function
public static double code(double wj, double x) {
double tmp;
if ((wj <= -5.5e-9) || !(wj <= 1.95e-10)) {
tmp = wj - ((wj - (x / Math.exp(wj))) / (wj + 1.0));
} else {
tmp = x + ((-2.0 * (wj * x)) + (wj * wj));
}
return tmp;
}
def code(wj, x): tmp = 0 if (wj <= -5.5e-9) or not (wj <= 1.95e-10): tmp = wj - ((wj - (x / math.exp(wj))) / (wj + 1.0)) else: tmp = x + ((-2.0 * (wj * x)) + (wj * wj)) return tmp
function code(wj, x) tmp = 0.0 if ((wj <= -5.5e-9) || !(wj <= 1.95e-10)) 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 * wj))); end return tmp end
function tmp_2 = code(wj, x) tmp = 0.0; if ((wj <= -5.5e-9) || ~((wj <= 1.95e-10))) tmp = wj - ((wj - (x / exp(wj))) / (wj + 1.0)); else tmp = x + ((-2.0 * (wj * x)) + (wj * wj)); end tmp_2 = tmp; end
code[wj_, x_] := If[Or[LessEqual[wj, -5.5e-9], N[Not[LessEqual[wj, 1.95e-10]], $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[(wj * wj), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq -5.5 \cdot 10^{-9} \lor \neg \left(wj \leq 1.95 \cdot 10^{-10}\right):\\
\;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\
\mathbf{else}:\\
\;\;\;\;x + \left(-2 \cdot \left(wj \cdot x\right) + wj \cdot wj\right)\\
\end{array}
\end{array}
if wj < -5.4999999999999996e-9 or 1.95e-10 < wj Initial program 52.5%
div-sub52.5%
associate-/l*52.7%
distribute-rgt1-in52.8%
associate-/l*52.9%
*-inverses62.9%
/-rgt-identity62.9%
distribute-rgt1-in93.0%
associate-/l/93.0%
div-sub92.9%
Simplified92.9%
if -5.4999999999999996e-9 < wj < 1.95e-10Initial program 73.8%
div-sub73.8%
associate-/l*73.8%
distribute-rgt1-in73.8%
associate-/l*73.8%
*-inverses73.8%
/-rgt-identity73.8%
distribute-rgt1-in73.8%
associate-/l/73.8%
div-sub73.8%
Simplified73.8%
Taylor expanded in wj around 0 100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in wj around 0 99.4%
unpow299.4%
Simplified99.4%
Final simplification98.9%
(FPCore (wj x) :precision binary64 (if (<= wj -1.55e-6) (- (+ wj (/ x (* (exp wj) (+ wj 1.0)))) (/ wj (+ wj 1.0))) (+ x (+ (* -2.0 (* wj x)) (fma wj wj (- (pow wj 3.0)))))))
double code(double wj, double x) {
double tmp;
if (wj <= -1.55e-6) {
tmp = (wj + (x / (exp(wj) * (wj + 1.0)))) - (wj / (wj + 1.0));
} else {
tmp = x + ((-2.0 * (wj * x)) + fma(wj, wj, -pow(wj, 3.0)));
}
return tmp;
}
function code(wj, x) tmp = 0.0 if (wj <= -1.55e-6) tmp = Float64(Float64(wj + Float64(x / Float64(exp(wj) * Float64(wj + 1.0)))) - Float64(wj / Float64(wj + 1.0))); else tmp = Float64(x + Float64(Float64(-2.0 * Float64(wj * x)) + fma(wj, wj, Float64(-(wj ^ 3.0))))); end return tmp end
code[wj_, x_] := If[LessEqual[wj, -1.55e-6], N[(N[(wj + N[(x / N[(N[Exp[wj], $MachinePrecision] * N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision] + N[(wj * wj + (-N[Power[wj, 3.0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq -1.55 \cdot 10^{-6}:\\
\;\;\;\;\left(wj + \frac{x}{e^{wj} \cdot \left(wj + 1\right)}\right) - \frac{wj}{wj + 1}\\
\mathbf{else}:\\
\;\;\;\;x + \left(-2 \cdot \left(wj \cdot x\right) + \mathsf{fma}\left(wj, wj, -{wj}^{3}\right)\right)\\
\end{array}
\end{array}
if wj < -1.55e-6Initial program 38.1%
div-sub38.1%
associate-/l*37.9%
distribute-rgt1-in38.1%
associate-/l*38.3%
*-inverses38.3%
/-rgt-identity38.3%
distribute-rgt1-in98.3%
associate-/l/98.3%
div-sub98.1%
Simplified98.1%
Taylor expanded in x around 0 98.3%
if -1.55e-6 < wj Initial program 73.5%
div-sub73.5%
associate-/l*73.5%
distribute-rgt1-in73.5%
associate-/l*73.5%
*-inverses74.4%
/-rgt-identity74.4%
distribute-rgt1-in74.4%
associate-/l/74.4%
div-sub74.4%
Simplified74.4%
Taylor expanded in wj around 0 97.9%
Taylor expanded in x around 0 97.9%
unpow297.9%
Simplified97.9%
Taylor expanded in x around 0 97.9%
Taylor expanded in wj around 0 97.9%
unpow297.9%
neg-mul-197.9%
+-commutative97.9%
fma-udef98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (wj x) :precision binary64 (if (<= wj -1.55e-6) (- (+ wj (/ x (* (exp wj) (+ wj 1.0)))) (/ wj (+ wj 1.0))) (+ x (+ (* -2.0 (* wj x)) (- (* wj wj) (pow wj 3.0))))))
double code(double wj, double x) {
double tmp;
if (wj <= -1.55e-6) {
tmp = (wj + (x / (exp(wj) * (wj + 1.0)))) - (wj / (wj + 1.0));
} else {
tmp = x + ((-2.0 * (wj * x)) + ((wj * wj) - pow(wj, 3.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.55d-6)) then
tmp = (wj + (x / (exp(wj) * (wj + 1.0d0)))) - (wj / (wj + 1.0d0))
else
tmp = x + (((-2.0d0) * (wj * x)) + ((wj * wj) - (wj ** 3.0d0)))
end if
code = tmp
end function
public static double code(double wj, double x) {
double tmp;
if (wj <= -1.55e-6) {
tmp = (wj + (x / (Math.exp(wj) * (wj + 1.0)))) - (wj / (wj + 1.0));
} else {
tmp = x + ((-2.0 * (wj * x)) + ((wj * wj) - Math.pow(wj, 3.0)));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= -1.55e-6: tmp = (wj + (x / (math.exp(wj) * (wj + 1.0)))) - (wj / (wj + 1.0)) else: tmp = x + ((-2.0 * (wj * x)) + ((wj * wj) - math.pow(wj, 3.0))) return tmp
function code(wj, x) tmp = 0.0 if (wj <= -1.55e-6) tmp = Float64(Float64(wj + Float64(x / Float64(exp(wj) * Float64(wj + 1.0)))) - Float64(wj / Float64(wj + 1.0))); else tmp = Float64(x + Float64(Float64(-2.0 * Float64(wj * x)) + Float64(Float64(wj * wj) - (wj ^ 3.0)))); end return tmp end
function tmp_2 = code(wj, x) tmp = 0.0; if (wj <= -1.55e-6) tmp = (wj + (x / (exp(wj) * (wj + 1.0)))) - (wj / (wj + 1.0)); else tmp = x + ((-2.0 * (wj * x)) + ((wj * wj) - (wj ^ 3.0))); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, -1.55e-6], N[(N[(wj + N[(x / N[(N[Exp[wj], $MachinePrecision] * N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision] + N[(N[(wj * wj), $MachinePrecision] - N[Power[wj, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq -1.55 \cdot 10^{-6}:\\
\;\;\;\;\left(wj + \frac{x}{e^{wj} \cdot \left(wj + 1\right)}\right) - \frac{wj}{wj + 1}\\
\mathbf{else}:\\
\;\;\;\;x + \left(-2 \cdot \left(wj \cdot x\right) + \left(wj \cdot wj - {wj}^{3}\right)\right)\\
\end{array}
\end{array}
if wj < -1.55e-6Initial program 38.1%
div-sub38.1%
associate-/l*37.9%
distribute-rgt1-in38.1%
associate-/l*38.3%
*-inverses38.3%
/-rgt-identity38.3%
distribute-rgt1-in98.3%
associate-/l/98.3%
div-sub98.1%
Simplified98.1%
Taylor expanded in x around 0 98.3%
if -1.55e-6 < wj Initial program 73.5%
div-sub73.5%
associate-/l*73.5%
distribute-rgt1-in73.5%
associate-/l*73.5%
*-inverses74.4%
/-rgt-identity74.4%
distribute-rgt1-in74.4%
associate-/l/74.4%
div-sub74.4%
Simplified74.4%
Taylor expanded in wj around 0 97.9%
Taylor expanded in x around 0 97.9%
unpow297.9%
Simplified97.9%
Taylor expanded in x around 0 97.9%
Taylor expanded in wj around 0 97.9%
unpow297.9%
neg-mul-197.9%
+-commutative97.9%
unsub-neg97.9%
Simplified97.9%
Final simplification98.0%
(FPCore (wj x) :precision binary64 (if (<= wj -1.55e-6) (- wj (/ (- wj (/ x (exp wj))) (+ wj 1.0))) (+ x (+ (* -2.0 (* wj x)) (- (* wj wj) (pow wj 3.0))))))
double code(double wj, double x) {
double tmp;
if (wj <= -1.55e-6) {
tmp = wj - ((wj - (x / exp(wj))) / (wj + 1.0));
} else {
tmp = x + ((-2.0 * (wj * x)) + ((wj * wj) - pow(wj, 3.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.55d-6)) then
tmp = wj - ((wj - (x / exp(wj))) / (wj + 1.0d0))
else
tmp = x + (((-2.0d0) * (wj * x)) + ((wj * wj) - (wj ** 3.0d0)))
end if
code = tmp
end function
public static double code(double wj, double x) {
double tmp;
if (wj <= -1.55e-6) {
tmp = wj - ((wj - (x / Math.exp(wj))) / (wj + 1.0));
} else {
tmp = x + ((-2.0 * (wj * x)) + ((wj * wj) - Math.pow(wj, 3.0)));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= -1.55e-6: tmp = wj - ((wj - (x / math.exp(wj))) / (wj + 1.0)) else: tmp = x + ((-2.0 * (wj * x)) + ((wj * wj) - math.pow(wj, 3.0))) return tmp
function code(wj, x) tmp = 0.0 if (wj <= -1.55e-6) 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(Float64(wj * wj) - (wj ^ 3.0)))); end return tmp end
function tmp_2 = code(wj, x) tmp = 0.0; if (wj <= -1.55e-6) tmp = wj - ((wj - (x / exp(wj))) / (wj + 1.0)); else tmp = x + ((-2.0 * (wj * x)) + ((wj * wj) - (wj ^ 3.0))); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, -1.55e-6], 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[(wj * wj), $MachinePrecision] - N[Power[wj, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq -1.55 \cdot 10^{-6}:\\
\;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{wj + 1}\\
\mathbf{else}:\\
\;\;\;\;x + \left(-2 \cdot \left(wj \cdot x\right) + \left(wj \cdot wj - {wj}^{3}\right)\right)\\
\end{array}
\end{array}
if wj < -1.55e-6Initial program 38.1%
div-sub38.1%
associate-/l*37.9%
distribute-rgt1-in38.1%
associate-/l*38.3%
*-inverses38.3%
/-rgt-identity38.3%
distribute-rgt1-in98.3%
associate-/l/98.3%
div-sub98.1%
Simplified98.1%
if -1.55e-6 < wj Initial program 73.5%
div-sub73.5%
associate-/l*73.5%
distribute-rgt1-in73.5%
associate-/l*73.5%
*-inverses74.4%
/-rgt-identity74.4%
distribute-rgt1-in74.4%
associate-/l/74.4%
div-sub74.4%
Simplified74.4%
Taylor expanded in wj around 0 97.9%
Taylor expanded in x around 0 97.9%
unpow297.9%
Simplified97.9%
Taylor expanded in x around 0 97.9%
Taylor expanded in wj around 0 97.9%
unpow297.9%
neg-mul-197.9%
+-commutative97.9%
unsub-neg97.9%
Simplified97.9%
Final simplification97.9%
(FPCore (wj x) :precision binary64 (if (<= wj -0.75) (/ x (* (exp wj) (+ wj 1.0))) (+ x (+ (* -2.0 (* wj x)) (* wj wj)))))
double code(double wj, double x) {
double tmp;
if (wj <= -0.75) {
tmp = x / (exp(wj) * (wj + 1.0));
} else {
tmp = x + ((-2.0 * (wj * x)) + (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 <= (-0.75d0)) then
tmp = x / (exp(wj) * (wj + 1.0d0))
else
tmp = x + (((-2.0d0) * (wj * x)) + (wj * wj))
end if
code = tmp
end function
public static double code(double wj, double x) {
double tmp;
if (wj <= -0.75) {
tmp = x / (Math.exp(wj) * (wj + 1.0));
} else {
tmp = x + ((-2.0 * (wj * x)) + (wj * wj));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= -0.75: tmp = x / (math.exp(wj) * (wj + 1.0)) else: tmp = x + ((-2.0 * (wj * x)) + (wj * wj)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= -0.75) tmp = Float64(x / Float64(exp(wj) * Float64(wj + 1.0))); else tmp = Float64(x + Float64(Float64(-2.0 * Float64(wj * x)) + Float64(wj * wj))); end return tmp end
function tmp_2 = code(wj, x) tmp = 0.0; if (wj <= -0.75) tmp = x / (exp(wj) * (wj + 1.0)); else tmp = x + ((-2.0 * (wj * x)) + (wj * wj)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, -0.75], N[(x / N[(N[Exp[wj], $MachinePrecision] * N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision] + N[(wj * wj), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq -0.75:\\
\;\;\;\;\frac{x}{e^{wj} \cdot \left(wj + 1\right)}\\
\mathbf{else}:\\
\;\;\;\;x + \left(-2 \cdot \left(wj \cdot x\right) + wj \cdot wj\right)\\
\end{array}
\end{array}
if wj < -0.75Initial program 13.9%
div-sub13.9%
associate-/l*13.9%
distribute-rgt1-in14.1%
associate-/l*14.3%
*-inverses14.3%
/-rgt-identity14.3%
distribute-rgt1-in100.0%
associate-/l/100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 86.4%
+-commutative86.4%
Simplified86.4%
if -0.75 < wj Initial program 73.7%
div-sub73.7%
associate-/l*73.8%
distribute-rgt1-in73.8%
associate-/l*73.8%
*-inverses74.6%
/-rgt-identity74.6%
distribute-rgt1-in74.6%
associate-/l/74.6%
div-sub74.6%
Simplified74.6%
Taylor expanded in wj around 0 97.4%
Taylor expanded in x around 0 97.3%
unpow297.3%
Simplified97.3%
Taylor expanded in x around 0 97.3%
Taylor expanded in wj around 0 96.1%
unpow296.1%
Simplified96.1%
Final simplification95.9%
(FPCore (wj x) :precision binary64 (if (<= wj -8.4e-63) (* wj wj) (if (<= wj 2e-8) (+ x (* -2.0 (* wj x))) (- wj (/ wj (+ wj 1.0))))))
double code(double wj, double x) {
double tmp;
if (wj <= -8.4e-63) {
tmp = wj * wj;
} else if (wj <= 2e-8) {
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 <= (-8.4d-63)) then
tmp = wj * wj
else if (wj <= 2d-8) 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 <= -8.4e-63) {
tmp = wj * wj;
} else if (wj <= 2e-8) {
tmp = x + (-2.0 * (wj * x));
} else {
tmp = wj - (wj / (wj + 1.0));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= -8.4e-63: tmp = wj * wj elif wj <= 2e-8: tmp = x + (-2.0 * (wj * x)) else: tmp = wj - (wj / (wj + 1.0)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= -8.4e-63) tmp = Float64(wj * wj); elseif (wj <= 2e-8) 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 <= -8.4e-63) tmp = wj * wj; elseif (wj <= 2e-8) tmp = x + (-2.0 * (wj * x)); else tmp = wj - (wj / (wj + 1.0)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, -8.4e-63], N[(wj * wj), $MachinePrecision], If[LessEqual[wj, 2e-8], 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 -8.4 \cdot 10^{-63}:\\
\;\;\;\;wj \cdot wj\\
\mathbf{elif}\;wj \leq 2 \cdot 10^{-8}:\\
\;\;\;\;x + -2 \cdot \left(wj \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\
\end{array}
\end{array}
if wj < -8.4e-63Initial program 38.0%
distribute-rgt1-in55.7%
Simplified55.7%
Taylor expanded in wj around 0 28.9%
*-commutative28.9%
Simplified28.9%
Taylor expanded in x around 0 10.4%
Taylor expanded in wj around 0 48.6%
unpow248.6%
Simplified48.6%
if -8.4e-63 < wj < 2e-8Initial program 77.9%
div-sub77.9%
associate-/l*77.8%
distribute-rgt1-in77.8%
associate-/l*77.8%
*-inverses77.8%
/-rgt-identity77.8%
distribute-rgt1-in77.8%
associate-/l/77.8%
div-sub77.8%
Simplified77.8%
Taylor expanded in wj around 0 91.5%
*-commutative91.5%
Simplified91.5%
if 2e-8 < wj Initial program 60.4%
div-sub60.4%
associate-/l*61.2%
distribute-rgt1-in61.2%
associate-/l*61.2%
*-inverses89.8%
/-rgt-identity89.8%
distribute-rgt1-in90.0%
associate-/l/90.0%
div-sub90.0%
Simplified90.0%
Taylor expanded in x around 0 75.9%
+-commutative75.9%
Simplified75.9%
Final simplification85.3%
(FPCore (wj x) :precision binary64 (+ x (+ (* -2.0 (* wj x)) (* wj wj))))
double code(double wj, double x) {
return x + ((-2.0 * (wj * x)) + (wj * wj));
}
real(8) function code(wj, x)
real(8), intent (in) :: wj
real(8), intent (in) :: x
code = x + (((-2.0d0) * (wj * x)) + (wj * wj))
end function
public static double code(double wj, double x) {
return x + ((-2.0 * (wj * x)) + (wj * wj));
}
def code(wj, x): return x + ((-2.0 * (wj * x)) + (wj * wj))
function code(wj, x) return Float64(x + Float64(Float64(-2.0 * Float64(wj * x)) + Float64(wj * wj))) end
function tmp = code(wj, x) tmp = x + ((-2.0 * (wj * x)) + (wj * wj)); end
code[wj_, x_] := N[(x + N[(N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision] + N[(wj * wj), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(-2 \cdot \left(wj \cdot x\right) + wj \cdot wj\right)
\end{array}
Initial program 72.1%
div-sub72.1%
associate-/l*72.2%
distribute-rgt1-in72.2%
associate-/l*72.2%
*-inverses72.9%
/-rgt-identity72.9%
distribute-rgt1-in75.3%
associate-/l/75.3%
div-sub75.3%
Simplified75.3%
Taylor expanded in wj around 0 94.8%
Taylor expanded in x around 0 94.7%
unpow294.7%
Simplified94.7%
Taylor expanded in x around 0 94.7%
Taylor expanded in wj around 0 93.5%
unpow293.5%
Simplified93.5%
Final simplification93.5%
(FPCore (wj x) :precision binary64 (if (<= wj -2.75e-61) (* wj wj) (+ x (* -2.0 (* wj x)))))
double code(double wj, double x) {
double tmp;
if (wj <= -2.75e-61) {
tmp = wj * wj;
} else {
tmp = x + (-2.0 * (wj * x));
}
return tmp;
}
real(8) function code(wj, x)
real(8), intent (in) :: wj
real(8), intent (in) :: x
real(8) :: tmp
if (wj <= (-2.75d-61)) then
tmp = wj * wj
else
tmp = x + ((-2.0d0) * (wj * x))
end if
code = tmp
end function
public static double code(double wj, double x) {
double tmp;
if (wj <= -2.75e-61) {
tmp = wj * wj;
} else {
tmp = x + (-2.0 * (wj * x));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= -2.75e-61: tmp = wj * wj else: tmp = x + (-2.0 * (wj * x)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= -2.75e-61) tmp = Float64(wj * wj); else tmp = Float64(x + Float64(-2.0 * Float64(wj * x))); end return tmp end
function tmp_2 = code(wj, x) tmp = 0.0; if (wj <= -2.75e-61) tmp = wj * wj; else tmp = x + (-2.0 * (wj * x)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, -2.75e-61], N[(wj * wj), $MachinePrecision], N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq -2.75 \cdot 10^{-61}:\\
\;\;\;\;wj \cdot wj\\
\mathbf{else}:\\
\;\;\;\;x + -2 \cdot \left(wj \cdot x\right)\\
\end{array}
\end{array}
if wj < -2.7499999999999998e-61Initial program 38.0%
distribute-rgt1-in55.7%
Simplified55.7%
Taylor expanded in wj around 0 28.9%
*-commutative28.9%
Simplified28.9%
Taylor expanded in x around 0 10.4%
Taylor expanded in wj around 0 48.6%
unpow248.6%
Simplified48.6%
if -2.7499999999999998e-61 < wj Initial program 77.3%
div-sub77.3%
associate-/l*77.3%
distribute-rgt1-in77.3%
associate-/l*77.3%
*-inverses78.2%
/-rgt-identity78.2%
distribute-rgt1-in78.2%
associate-/l/78.2%
div-sub78.2%
Simplified78.2%
Taylor expanded in wj around 0 88.7%
*-commutative88.7%
Simplified88.7%
Final simplification83.4%
(FPCore (wj x) :precision binary64 (if (<= wj -2.8e-61) (* wj wj) x))
double code(double wj, double x) {
double tmp;
if (wj <= -2.8e-61) {
tmp = wj * wj;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(wj, x)
real(8), intent (in) :: wj
real(8), intent (in) :: x
real(8) :: tmp
if (wj <= (-2.8d-61)) then
tmp = wj * wj
else
tmp = x
end if
code = tmp
end function
public static double code(double wj, double x) {
double tmp;
if (wj <= -2.8e-61) {
tmp = wj * wj;
} else {
tmp = x;
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= -2.8e-61: tmp = wj * wj else: tmp = x return tmp
function code(wj, x) tmp = 0.0 if (wj <= -2.8e-61) tmp = Float64(wj * wj); else tmp = x; end return tmp end
function tmp_2 = code(wj, x) tmp = 0.0; if (wj <= -2.8e-61) tmp = wj * wj; else tmp = x; end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, -2.8e-61], N[(wj * wj), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq -2.8 \cdot 10^{-61}:\\
\;\;\;\;wj \cdot wj\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if wj < -2.8000000000000001e-61Initial program 38.0%
distribute-rgt1-in55.7%
Simplified55.7%
Taylor expanded in wj around 0 28.9%
*-commutative28.9%
Simplified28.9%
Taylor expanded in x around 0 10.4%
Taylor expanded in wj around 0 48.6%
unpow248.6%
Simplified48.6%
if -2.8000000000000001e-61 < wj Initial program 77.3%
div-sub77.3%
associate-/l*77.3%
distribute-rgt1-in77.3%
associate-/l*77.3%
*-inverses78.2%
/-rgt-identity78.2%
distribute-rgt1-in78.2%
associate-/l/78.2%
div-sub78.2%
Simplified78.2%
Taylor expanded in wj around 0 88.4%
Final simplification83.1%
(FPCore (wj x) :precision binary64 -0.5)
double code(double wj, double x) {
return -0.5;
}
real(8) function code(wj, x)
real(8), intent (in) :: wj
real(8), intent (in) :: x
code = -0.5d0
end function
public static double code(double wj, double x) {
return -0.5;
}
def code(wj, x): return -0.5
function code(wj, x) return -0.5 end
function tmp = code(wj, x) tmp = -0.5; end
code[wj_, x_] := -0.5
\begin{array}{l}
\\
-0.5
\end{array}
Initial program 72.1%
distribute-rgt1-in74.4%
Simplified74.4%
Taylor expanded in wj around 0 69.7%
*-commutative69.7%
Simplified69.7%
Taylor expanded in wj around inf 3.3%
*-commutative3.3%
Simplified3.3%
Taylor expanded in wj around 0 3.3%
Final simplification3.3%
(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 72.1%
div-sub72.1%
associate-/l*72.2%
distribute-rgt1-in72.2%
associate-/l*72.2%
*-inverses72.9%
/-rgt-identity72.9%
distribute-rgt1-in75.3%
associate-/l/75.3%
div-sub75.3%
Simplified75.3%
Taylor expanded in wj around inf 4.4%
Final simplification4.4%
(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 72.1%
div-sub72.1%
associate-/l*72.2%
distribute-rgt1-in72.2%
associate-/l*72.2%
*-inverses72.9%
/-rgt-identity72.9%
distribute-rgt1-in75.3%
associate-/l/75.3%
div-sub75.3%
Simplified75.3%
Taylor expanded in wj around 0 79.8%
Final simplification79.8%
(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 2023283
(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))))))