
(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 11 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 (- (/ x (exp wj)) wj)))
(if (<= wj -5.2e-9)
(+ wj (/ t_0 (+ wj 1.0)))
(if (<= wj 9e-9)
(+ (+ x (* -2.0 (* wj x))) (+ (* wj wj) (* 4.0 (* x (* wj wj)))))
(+ wj (/ 1.0 (/ (+ wj 1.0) t_0)))))))
double code(double wj, double x) {
double t_0 = (x / exp(wj)) - wj;
double tmp;
if (wj <= -5.2e-9) {
tmp = wj + (t_0 / (wj + 1.0));
} else if (wj <= 9e-9) {
tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * wj))));
} else {
tmp = wj + (1.0 / ((wj + 1.0) / t_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 = (x / exp(wj)) - wj
if (wj <= (-5.2d-9)) then
tmp = wj + (t_0 / (wj + 1.0d0))
else if (wj <= 9d-9) then
tmp = (x + ((-2.0d0) * (wj * x))) + ((wj * wj) + (4.0d0 * (x * (wj * wj))))
else
tmp = wj + (1.0d0 / ((wj + 1.0d0) / t_0))
end if
code = tmp
end function
public static double code(double wj, double x) {
double t_0 = (x / Math.exp(wj)) - wj;
double tmp;
if (wj <= -5.2e-9) {
tmp = wj + (t_0 / (wj + 1.0));
} else if (wj <= 9e-9) {
tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * wj))));
} else {
tmp = wj + (1.0 / ((wj + 1.0) / t_0));
}
return tmp;
}
def code(wj, x): t_0 = (x / math.exp(wj)) - wj tmp = 0 if wj <= -5.2e-9: tmp = wj + (t_0 / (wj + 1.0)) elif wj <= 9e-9: tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * wj)))) else: tmp = wj + (1.0 / ((wj + 1.0) / t_0)) return tmp
function code(wj, x) t_0 = Float64(Float64(x / exp(wj)) - wj) tmp = 0.0 if (wj <= -5.2e-9) tmp = Float64(wj + Float64(t_0 / Float64(wj + 1.0))); elseif (wj <= 9e-9) tmp = Float64(Float64(x + Float64(-2.0 * Float64(wj * x))) + Float64(Float64(wj * wj) + Float64(4.0 * Float64(x * Float64(wj * wj))))); else tmp = Float64(wj + Float64(1.0 / Float64(Float64(wj + 1.0) / t_0))); end return tmp end
function tmp_2 = code(wj, x) t_0 = (x / exp(wj)) - wj; tmp = 0.0; if (wj <= -5.2e-9) tmp = wj + (t_0 / (wj + 1.0)); elseif (wj <= 9e-9) tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * wj)))); else tmp = wj + (1.0 / ((wj + 1.0) / t_0)); end tmp_2 = tmp; end
code[wj_, x_] := Block[{t$95$0 = N[(N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision]}, If[LessEqual[wj, -5.2e-9], N[(wj + N[(t$95$0 / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[wj, 9e-9], N[(N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(wj * wj), $MachinePrecision] + N[(4.0 * N[(x * N[(wj * wj), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(wj + N[(1.0 / N[(N[(wj + 1.0), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{e^{wj}} - wj\\
\mathbf{if}\;wj \leq -5.2 \cdot 10^{-9}:\\
\;\;\;\;wj + \frac{t_0}{wj + 1}\\
\mathbf{elif}\;wj \leq 9 \cdot 10^{-9}:\\
\;\;\;\;\left(x + -2 \cdot \left(wj \cdot x\right)\right) + \left(wj \cdot wj + 4 \cdot \left(x \cdot \left(wj \cdot wj\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{1}{\frac{wj + 1}{t_0}}\\
\end{array}
\end{array}
if wj < -5.2000000000000002e-9Initial program 35.0%
sub-neg35.0%
div-sub35.0%
sub-neg35.0%
+-commutative35.0%
distribute-neg-in35.0%
remove-double-neg35.0%
sub-neg35.0%
div-sub35.0%
distribute-rgt1-in95.0%
associate-/l/95.0%
Simplified95.0%
if -5.2000000000000002e-9 < wj < 8.99999999999999953e-9Initial program 80.2%
distribute-rgt1-in80.2%
Simplified80.2%
Taylor expanded in wj around 0 80.2%
*-commutative80.2%
Simplified80.2%
Taylor expanded in wj around 0 99.2%
Taylor expanded in x around 0 99.7%
unpow299.7%
*-commutative99.7%
unpow299.7%
Simplified99.7%
if 8.99999999999999953e-9 < wj Initial program 42.6%
sub-neg42.6%
div-sub42.6%
sub-neg42.6%
+-commutative42.6%
distribute-neg-in42.6%
remove-double-neg42.6%
sub-neg42.6%
div-sub42.6%
distribute-rgt1-in42.6%
associate-/l/42.4%
Simplified99.6%
clear-num99.8%
inv-pow99.8%
Applied egg-rr99.8%
unpow-199.8%
Simplified99.8%
Final simplification99.6%
(FPCore (wj x)
:precision binary64
(let* ((t_0 (* wj (exp wj))))
(if (<= (+ wj (/ (- x t_0) (+ (exp wj) t_0))) 5e-20)
(+ (* 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 + ((x - t_0) / (exp(wj) + t_0))) <= 5e-20) {
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 + ((x - t_0) / (exp(wj) + t_0))) <= 5d-20) 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 + ((x - t_0) / (Math.exp(wj) + t_0))) <= 5e-20) {
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 + ((x - t_0) / (math.exp(wj) + t_0))) <= 5e-20: 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(x - t_0) / Float64(exp(wj) + t_0))) <= 5e-20) tmp = Float64(Float64(wj * wj) + Float64(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 + ((x - t_0) / (exp(wj) + t_0))) <= 5e-20) 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[(x - t$95$0), $MachinePrecision] / N[(N[Exp[wj], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-20], N[(N[(wj * wj), $MachinePrecision] + N[(N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Power[wj, 3.0], $MachinePrecision]), $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 5 \cdot 10^{-20}:\\
\;\;\;\;wj \cdot wj + \left(\left(x + -2 \cdot \left(wj \cdot x\right)\right) - {wj}^{3}\right)\\
\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))))) < 4.9999999999999999e-20Initial program 72.5%
sub-neg72.5%
div-sub72.5%
sub-neg72.5%
+-commutative72.5%
distribute-neg-in72.5%
remove-double-neg72.5%
sub-neg72.5%
div-sub72.5%
distribute-rgt1-in73.1%
associate-/l/73.0%
Simplified73.0%
Taylor expanded in wj around 0 72.5%
+-commutative72.5%
mul-1-neg72.5%
unsub-neg72.5%
*-commutative72.5%
Simplified72.5%
Taylor expanded in wj around 0 99.5%
Taylor expanded in x around 0 99.5%
unpow299.5%
Simplified99.5%
Taylor expanded in x around 0 99.5%
mul-1-neg99.5%
Simplified99.5%
if 4.9999999999999999e-20 < (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) Initial program 91.9%
sub-neg91.9%
div-sub91.9%
sub-neg91.9%
+-commutative91.9%
distribute-neg-in91.9%
remove-double-neg91.9%
sub-neg91.9%
div-sub91.9%
distribute-rgt1-in94.5%
associate-/l/94.4%
Simplified99.6%
Final simplification99.5%
(FPCore (wj x) :precision binary64 (if (or (<= wj -6e-9) (not (<= wj 8e-9))) (+ wj (/ (- (/ x (exp wj)) wj) (+ wj 1.0))) (+ (+ x (* -2.0 (* wj x))) (+ (* wj wj) (* 4.0 (* x (* wj wj)))))))
double code(double wj, double x) {
double tmp;
if ((wj <= -6e-9) || !(wj <= 8e-9)) {
tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0));
} else {
tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (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 <= (-6d-9)) .or. (.not. (wj <= 8d-9))) then
tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0d0))
else
tmp = (x + ((-2.0d0) * (wj * x))) + ((wj * wj) + (4.0d0 * (x * (wj * wj))))
end if
code = tmp
end function
public static double code(double wj, double x) {
double tmp;
if ((wj <= -6e-9) || !(wj <= 8e-9)) {
tmp = wj + (((x / Math.exp(wj)) - wj) / (wj + 1.0));
} else {
tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * wj))));
}
return tmp;
}
def code(wj, x): tmp = 0 if (wj <= -6e-9) or not (wj <= 8e-9): tmp = wj + (((x / math.exp(wj)) - wj) / (wj + 1.0)) else: tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * wj)))) return tmp
function code(wj, x) tmp = 0.0 if ((wj <= -6e-9) || !(wj <= 8e-9)) tmp = Float64(wj + Float64(Float64(Float64(x / exp(wj)) - wj) / Float64(wj + 1.0))); else tmp = Float64(Float64(x + Float64(-2.0 * Float64(wj * x))) + Float64(Float64(wj * wj) + Float64(4.0 * Float64(x * Float64(wj * wj))))); end return tmp end
function tmp_2 = code(wj, x) tmp = 0.0; if ((wj <= -6e-9) || ~((wj <= 8e-9))) tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0)); else tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * wj)))); end tmp_2 = tmp; end
code[wj_, x_] := If[Or[LessEqual[wj, -6e-9], N[Not[LessEqual[wj, 8e-9]], $MachinePrecision]], N[(wj + N[(N[(N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision] - wj), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(wj * wj), $MachinePrecision] + N[(4.0 * N[(x * N[(wj * wj), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq -6 \cdot 10^{-9} \lor \neg \left(wj \leq 8 \cdot 10^{-9}\right):\\
\;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\
\mathbf{else}:\\
\;\;\;\;\left(x + -2 \cdot \left(wj \cdot x\right)\right) + \left(wj \cdot wj + 4 \cdot \left(x \cdot \left(wj \cdot wj\right)\right)\right)\\
\end{array}
\end{array}
if wj < -5.99999999999999996e-9 or 8.0000000000000005e-9 < wj Initial program 39.4%
sub-neg39.4%
div-sub39.4%
sub-neg39.4%
+-commutative39.4%
distribute-neg-in39.4%
remove-double-neg39.4%
sub-neg39.4%
div-sub39.4%
distribute-rgt1-in64.4%
associate-/l/64.3%
Simplified97.6%
if -5.99999999999999996e-9 < wj < 8.0000000000000005e-9Initial program 80.2%
distribute-rgt1-in80.2%
Simplified80.2%
Taylor expanded in wj around 0 80.2%
*-commutative80.2%
Simplified80.2%
Taylor expanded in wj around 0 99.2%
Taylor expanded in x around 0 99.7%
unpow299.7%
*-commutative99.7%
unpow299.7%
Simplified99.7%
Final simplification99.6%
(FPCore (wj x) :precision binary64 (if (<= wj 0.0048) (+ (+ x (* -2.0 (* wj x))) (+ (* wj wj) (* 4.0 (* x (* wj wj))))) (- wj (/ wj (+ wj 1.0)))))
double code(double wj, double x) {
double tmp;
if (wj <= 0.0048) {
tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * 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 <= 0.0048d0) then
tmp = (x + ((-2.0d0) * (wj * x))) + ((wj * wj) + (4.0d0 * (x * (wj * 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 <= 0.0048) {
tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * wj))));
} else {
tmp = wj - (wj / (wj + 1.0));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= 0.0048: tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * wj)))) else: tmp = wj - (wj / (wj + 1.0)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= 0.0048) tmp = Float64(Float64(x + Float64(-2.0 * Float64(wj * x))) + Float64(Float64(wj * wj) + Float64(4.0 * Float64(x * Float64(wj * 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 <= 0.0048) tmp = (x + (-2.0 * (wj * x))) + ((wj * wj) + (4.0 * (x * (wj * wj)))); else tmp = wj - (wj / (wj + 1.0)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, 0.0048], N[(N[(x + N[(-2.0 * N[(wj * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(wj * wj), $MachinePrecision] + N[(4.0 * N[(x * N[(wj * wj), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(wj - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq 0.0048:\\
\;\;\;\;\left(x + -2 \cdot \left(wj \cdot x\right)\right) + \left(wj \cdot wj + 4 \cdot \left(x \cdot \left(wj \cdot wj\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\
\end{array}
\end{array}
if wj < 0.00479999999999999958Initial program 79.4%
distribute-rgt1-in80.6%
Simplified80.6%
Taylor expanded in wj around 0 78.8%
*-commutative78.8%
Simplified78.8%
Taylor expanded in wj around 0 97.3%
Taylor expanded in x around 0 97.7%
unpow297.7%
*-commutative97.7%
unpow297.7%
Simplified97.7%
if 0.00479999999999999958 < wj Initial program 33.3%
sub-neg33.3%
div-sub33.3%
sub-neg33.3%
+-commutative33.3%
distribute-neg-in33.3%
remove-double-neg33.3%
sub-neg33.3%
div-sub33.3%
distribute-rgt1-in33.3%
associate-/l/33.1%
Simplified99.7%
Taylor expanded in x around 0 84.2%
+-commutative84.2%
Simplified84.2%
Final simplification97.4%
(FPCore (wj x) :precision binary64 (if (<= wj 0.00028) (* x (* (- 1.0 wj) (/ 1.0 (+ wj 1.0)))) (- wj (/ wj (+ wj 1.0)))))
double code(double wj, double x) {
double tmp;
if (wj <= 0.00028) {
tmp = x * ((1.0 - wj) * (1.0 / (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 <= 0.00028d0) then
tmp = x * ((1.0d0 - wj) * (1.0d0 / (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 <= 0.00028) {
tmp = x * ((1.0 - wj) * (1.0 / (wj + 1.0)));
} else {
tmp = wj - (wj / (wj + 1.0));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= 0.00028: tmp = x * ((1.0 - wj) * (1.0 / (wj + 1.0))) else: tmp = wj - (wj / (wj + 1.0)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= 0.00028) tmp = Float64(x * Float64(Float64(1.0 - wj) * Float64(1.0 / 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 <= 0.00028) tmp = x * ((1.0 - wj) * (1.0 / (wj + 1.0))); else tmp = wj - (wj / (wj + 1.0)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, 0.00028], N[(x * N[(N[(1.0 - wj), $MachinePrecision] * N[(1.0 / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(wj - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq 0.00028:\\
\;\;\;\;x \cdot \left(\left(1 - wj\right) \cdot \frac{1}{wj + 1}\right)\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\
\end{array}
\end{array}
if wj < 2.7999999999999998e-4Initial program 79.4%
sub-neg79.4%
div-sub79.4%
sub-neg79.4%
+-commutative79.4%
distribute-neg-in79.4%
remove-double-neg79.4%
sub-neg79.4%
div-sub79.4%
distribute-rgt1-in80.6%
associate-/l/80.6%
Simplified80.6%
Taylor expanded in wj around 0 78.9%
+-commutative78.9%
mul-1-neg78.9%
unsub-neg78.9%
*-commutative78.9%
Simplified78.9%
Taylor expanded in x around inf 88.0%
sub-neg88.0%
+-commutative88.0%
+-commutative88.0%
Applied egg-rr88.0%
unsub-neg88.0%
div-sub88.0%
Simplified88.0%
div-inv88.0%
+-commutative88.0%
Applied egg-rr88.0%
if 2.7999999999999998e-4 < wj Initial program 33.3%
sub-neg33.3%
div-sub33.3%
sub-neg33.3%
+-commutative33.3%
distribute-neg-in33.3%
remove-double-neg33.3%
sub-neg33.3%
div-sub33.3%
distribute-rgt1-in33.3%
associate-/l/33.1%
Simplified99.7%
Taylor expanded in x around 0 84.2%
+-commutative84.2%
Simplified84.2%
Final simplification87.9%
(FPCore (wj x) :precision binary64 (if (<= wj 0.00075) (* x (/ (- 1.0 wj) (+ wj 1.0))) (- wj (/ wj (+ wj 1.0)))))
double code(double wj, double x) {
double tmp;
if (wj <= 0.00075) {
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 <= 0.00075d0) 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 <= 0.00075) {
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 <= 0.00075: 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 <= 0.00075) tmp = Float64(x * Float64(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 <= 0.00075) 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, 0.00075], N[(x * N[(N[(1.0 - wj), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(wj - N[(wj / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;wj \leq 0.00075:\\
\;\;\;\;x \cdot \frac{1 - wj}{wj + 1}\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\
\end{array}
\end{array}
if wj < 7.5000000000000002e-4Initial program 79.4%
sub-neg79.4%
div-sub79.4%
sub-neg79.4%
+-commutative79.4%
distribute-neg-in79.4%
remove-double-neg79.4%
sub-neg79.4%
div-sub79.4%
distribute-rgt1-in80.6%
associate-/l/80.6%
Simplified80.6%
Taylor expanded in wj around 0 78.9%
+-commutative78.9%
mul-1-neg78.9%
unsub-neg78.9%
*-commutative78.9%
Simplified78.9%
Taylor expanded in x around inf 88.0%
sub-neg88.0%
+-commutative88.0%
+-commutative88.0%
Applied egg-rr88.0%
unsub-neg88.0%
div-sub88.0%
Simplified88.0%
if 7.5000000000000002e-4 < wj Initial program 33.3%
sub-neg33.3%
div-sub33.3%
sub-neg33.3%
+-commutative33.3%
distribute-neg-in33.3%
remove-double-neg33.3%
sub-neg33.3%
div-sub33.3%
distribute-rgt1-in33.3%
associate-/l/33.1%
Simplified99.7%
Taylor expanded in x around 0 84.2%
+-commutative84.2%
Simplified84.2%
Final simplification87.9%
(FPCore (wj x) :precision binary64 (if (<= wj 0.005) (+ x (* -2.0 (* wj x))) (- wj (/ wj (+ wj 1.0)))))
double code(double wj, double x) {
double tmp;
if (wj <= 0.005) {
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 <= 0.005d0) 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 <= 0.005) {
tmp = x + (-2.0 * (wj * x));
} else {
tmp = wj - (wj / (wj + 1.0));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= 0.005: tmp = x + (-2.0 * (wj * x)) else: tmp = wj - (wj / (wj + 1.0)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= 0.005) 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 <= 0.005) tmp = x + (-2.0 * (wj * x)); else tmp = wj - (wj / (wj + 1.0)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, 0.005], 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 0.005:\\
\;\;\;\;x + -2 \cdot \left(wj \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\
\end{array}
\end{array}
if wj < 0.0050000000000000001Initial program 79.4%
sub-neg79.4%
div-sub79.4%
sub-neg79.4%
+-commutative79.4%
distribute-neg-in79.4%
remove-double-neg79.4%
sub-neg79.4%
div-sub79.4%
distribute-rgt1-in80.6%
associate-/l/80.6%
Simplified80.6%
Taylor expanded in wj around 0 87.9%
if 0.0050000000000000001 < wj Initial program 33.3%
sub-neg33.3%
div-sub33.3%
sub-neg33.3%
+-commutative33.3%
distribute-neg-in33.3%
remove-double-neg33.3%
sub-neg33.3%
div-sub33.3%
distribute-rgt1-in33.3%
associate-/l/33.1%
Simplified99.7%
Taylor expanded in x around 0 84.2%
+-commutative84.2%
Simplified84.2%
Final simplification87.8%
(FPCore (wj x) :precision binary64 (if (<= wj 0.0005) (/ x (+ (* wj 2.0) 1.0)) (- wj (/ wj (+ wj 1.0)))))
double code(double wj, double x) {
double tmp;
if (wj <= 0.0005) {
tmp = x / ((wj * 2.0) + 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 <= 0.0005d0) then
tmp = x / ((wj * 2.0d0) + 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 <= 0.0005) {
tmp = x / ((wj * 2.0) + 1.0);
} else {
tmp = wj - (wj / (wj + 1.0));
}
return tmp;
}
def code(wj, x): tmp = 0 if wj <= 0.0005: tmp = x / ((wj * 2.0) + 1.0) else: tmp = wj - (wj / (wj + 1.0)) return tmp
function code(wj, x) tmp = 0.0 if (wj <= 0.0005) tmp = Float64(x / Float64(Float64(wj * 2.0) + 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 <= 0.0005) tmp = x / ((wj * 2.0) + 1.0); else tmp = wj - (wj / (wj + 1.0)); end tmp_2 = tmp; end
code[wj_, x_] := If[LessEqual[wj, 0.0005], N[(x / N[(N[(wj * 2.0), $MachinePrecision] + 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 0.0005:\\
\;\;\;\;\frac{x}{wj \cdot 2 + 1}\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{wj}{wj + 1}\\
\end{array}
\end{array}
if wj < 5.0000000000000001e-4Initial program 79.4%
distribute-rgt1-in80.6%
Simplified80.6%
Taylor expanded in wj around 0 78.8%
*-commutative78.8%
Simplified78.8%
Taylor expanded in x around inf 88.0%
*-commutative88.0%
Simplified88.0%
if 5.0000000000000001e-4 < wj Initial program 33.3%
sub-neg33.3%
div-sub33.3%
sub-neg33.3%
+-commutative33.3%
distribute-neg-in33.3%
remove-double-neg33.3%
sub-neg33.3%
div-sub33.3%
distribute-rgt1-in33.3%
associate-/l/33.1%
Simplified99.7%
Taylor expanded in x around 0 84.2%
+-commutative84.2%
Simplified84.2%
Final simplification87.9%
(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 78.3%
sub-neg78.3%
div-sub78.3%
sub-neg78.3%
+-commutative78.3%
distribute-neg-in78.3%
remove-double-neg78.3%
sub-neg78.3%
div-sub78.3%
distribute-rgt1-in79.5%
associate-/l/79.5%
Simplified81.0%
Taylor expanded in wj around 0 85.9%
Final simplification85.9%
(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 78.3%
sub-neg78.3%
div-sub78.3%
sub-neg78.3%
+-commutative78.3%
distribute-neg-in78.3%
remove-double-neg78.3%
sub-neg78.3%
div-sub78.3%
distribute-rgt1-in79.5%
associate-/l/79.5%
Simplified81.0%
Taylor expanded in wj around inf 4.8%
Final simplification4.8%
(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 78.3%
sub-neg78.3%
div-sub78.3%
sub-neg78.3%
+-commutative78.3%
distribute-neg-in78.3%
remove-double-neg78.3%
sub-neg78.3%
div-sub78.3%
distribute-rgt1-in79.5%
associate-/l/79.5%
Simplified81.0%
Taylor expanded in wj around 0 85.7%
Final simplification85.7%
(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 2023199
(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))))))