
(FPCore (w l) :precision binary64 (* (exp (- w)) (pow l (exp w))))
double code(double w, double l) {
return exp(-w) * pow(l, exp(w));
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
code = exp(-w) * (l ** exp(w))
end function
public static double code(double w, double l) {
return Math.exp(-w) * Math.pow(l, Math.exp(w));
}
def code(w, l): return math.exp(-w) * math.pow(l, math.exp(w))
function code(w, l) return Float64(exp(Float64(-w)) * (l ^ exp(w))) end
function tmp = code(w, l) tmp = exp(-w) * (l ^ exp(w)); end
code[w_, l_] := N[(N[Exp[(-w)], $MachinePrecision] * N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{-w} \cdot {\ell}^{\left(e^{w}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (w l) :precision binary64 (* (exp (- w)) (pow l (exp w))))
double code(double w, double l) {
return exp(-w) * pow(l, exp(w));
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
code = exp(-w) * (l ** exp(w))
end function
public static double code(double w, double l) {
return Math.exp(-w) * Math.pow(l, Math.exp(w));
}
def code(w, l): return math.exp(-w) * math.pow(l, math.exp(w))
function code(w, l) return Float64(exp(Float64(-w)) * (l ^ exp(w))) end
function tmp = code(w, l) tmp = exp(-w) * (l ^ exp(w)); end
code[w_, l_] := N[(N[Exp[(-w)], $MachinePrecision] * N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{-w} \cdot {\ell}^{\left(e^{w}\right)}
\end{array}
(FPCore (w l) :precision binary64 (/ (/ (pow l (exp w)) (cbrt (exp w))) (cbrt (exp (+ w w)))))
double code(double w, double l) {
return (pow(l, exp(w)) / cbrt(exp(w))) / cbrt(exp((w + w)));
}
public static double code(double w, double l) {
return (Math.pow(l, Math.exp(w)) / Math.cbrt(Math.exp(w))) / Math.cbrt(Math.exp((w + w)));
}
function code(w, l) return Float64(Float64((l ^ exp(w)) / cbrt(exp(w))) / cbrt(exp(Float64(w + w)))) end
code[w_, l_] := N[(N[(N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision] / N[Power[N[Exp[w], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] / N[Power[N[Exp[N[(w + w), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{{\ell}^{\left(e^{w}\right)}}{\sqrt[3]{e^{w}}}}{\sqrt[3]{e^{w + w}}}
\end{array}
Initial program 99.5%
exp-neg99.5%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
*-un-lft-identity99.5%
add-cube-cbrt99.5%
times-frac99.5%
cbrt-unprod99.5%
prod-exp99.5%
Applied egg-rr99.5%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (w l) :precision binary64 (/ (pow l (exp w)) (exp w)))
double code(double w, double l) {
return pow(l, exp(w)) / exp(w);
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
code = (l ** exp(w)) / exp(w)
end function
public static double code(double w, double l) {
return Math.pow(l, Math.exp(w)) / Math.exp(w);
}
def code(w, l): return math.pow(l, math.exp(w)) / math.exp(w)
function code(w, l) return Float64((l ^ exp(w)) / exp(w)) end
function tmp = code(w, l) tmp = (l ^ exp(w)) / exp(w); end
code[w_, l_] := N[(N[Power[l, N[Exp[w], $MachinePrecision]], $MachinePrecision] / N[Exp[w], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\ell}^{\left(e^{w}\right)}}{e^{w}}
\end{array}
Initial program 99.5%
exp-neg99.5%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (w l) :precision binary64 (/ l (cbrt (exp (+ w w)))))
double code(double w, double l) {
return l / cbrt(exp((w + w)));
}
public static double code(double w, double l) {
return l / Math.cbrt(Math.exp((w + w)));
}
function code(w, l) return Float64(l / cbrt(exp(Float64(w + w)))) end
code[w_, l_] := N[(l / N[Power[N[Exp[N[(w + w), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\ell}{\sqrt[3]{e^{w + w}}}
\end{array}
Initial program 99.5%
exp-neg99.5%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
*-un-lft-identity99.5%
add-cube-cbrt99.5%
times-frac99.5%
cbrt-unprod99.5%
prod-exp99.5%
Applied egg-rr99.5%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Taylor expanded in w around 0 98.7%
Final simplification98.7%
(FPCore (w l) :precision binary64 (/ l (pow (exp w) 0.6666666666666666)))
double code(double w, double l) {
return l / pow(exp(w), 0.6666666666666666);
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
code = l / (exp(w) ** 0.6666666666666666d0)
end function
public static double code(double w, double l) {
return l / Math.pow(Math.exp(w), 0.6666666666666666);
}
def code(w, l): return l / math.pow(math.exp(w), 0.6666666666666666)
function code(w, l) return Float64(l / (exp(w) ^ 0.6666666666666666)) end
function tmp = code(w, l) tmp = l / (exp(w) ^ 0.6666666666666666); end
code[w_, l_] := N[(l / N[Power[N[Exp[w], $MachinePrecision], 0.6666666666666666], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\ell}{{\left(e^{w}\right)}^{0.6666666666666666}}
\end{array}
Initial program 99.5%
exp-neg99.5%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
*-un-lft-identity99.5%
add-cube-cbrt99.5%
times-frac99.5%
cbrt-unprod99.5%
prod-exp99.5%
Applied egg-rr99.5%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Taylor expanded in w around 0 98.7%
pow1/398.7%
exp-sum98.7%
pow-prod-down98.4%
pow-prod-up98.4%
metadata-eval98.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (w l) :precision binary64 (if (<= w -31.0) (/ l 0.0) (if (<= w 0.0195) (+ l (* w (- (* l (log l)) l))) (+ (+ l 1.0) -1.0))))
double code(double w, double l) {
double tmp;
if (w <= -31.0) {
tmp = l / 0.0;
} else if (w <= 0.0195) {
tmp = l + (w * ((l * log(l)) - l));
} else {
tmp = (l + 1.0) + -1.0;
}
return tmp;
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
real(8) :: tmp
if (w <= (-31.0d0)) then
tmp = l / 0.0d0
else if (w <= 0.0195d0) then
tmp = l + (w * ((l * log(l)) - l))
else
tmp = (l + 1.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double w, double l) {
double tmp;
if (w <= -31.0) {
tmp = l / 0.0;
} else if (w <= 0.0195) {
tmp = l + (w * ((l * Math.log(l)) - l));
} else {
tmp = (l + 1.0) + -1.0;
}
return tmp;
}
def code(w, l): tmp = 0 if w <= -31.0: tmp = l / 0.0 elif w <= 0.0195: tmp = l + (w * ((l * math.log(l)) - l)) else: tmp = (l + 1.0) + -1.0 return tmp
function code(w, l) tmp = 0.0 if (w <= -31.0) tmp = Float64(l / 0.0); elseif (w <= 0.0195) tmp = Float64(l + Float64(w * Float64(Float64(l * log(l)) - l))); else tmp = Float64(Float64(l + 1.0) + -1.0); end return tmp end
function tmp_2 = code(w, l) tmp = 0.0; if (w <= -31.0) tmp = l / 0.0; elseif (w <= 0.0195) tmp = l + (w * ((l * log(l)) - l)); else tmp = (l + 1.0) + -1.0; end tmp_2 = tmp; end
code[w_, l_] := If[LessEqual[w, -31.0], N[(l / 0.0), $MachinePrecision], If[LessEqual[w, 0.0195], N[(l + N[(w * N[(N[(l * N[Log[l], $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(l + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;w \leq -31:\\
\;\;\;\;\frac{\ell}{0}\\
\mathbf{elif}\;w \leq 0.0195:\\
\;\;\;\;\ell + w \cdot \left(\ell \cdot \log \ell - \ell\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\ell + 1\right) + -1\\
\end{array}
\end{array}
if w < -31Initial program 100.0%
exp-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
Simplified100.0%
*-un-lft-identity100.0%
add-cube-cbrt100.0%
times-frac100.0%
cbrt-unprod100.0%
prod-exp100.0%
Applied egg-rr100.0%
associate-*l/100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in w around 0 100.0%
Taylor expanded in w around 0 3.7%
Simplified100.0%
if -31 < w < 0.0195Initial program 99.7%
exp-neg99.7%
associate-*l/99.7%
*-lft-identity99.7%
Simplified99.7%
Taylor expanded in w around 0 99.0%
if 0.0195 < w Initial program 97.8%
exp-neg97.8%
associate-*l/97.8%
*-lft-identity97.8%
Simplified97.8%
expm1-log1p-u97.8%
Applied egg-rr97.8%
Taylor expanded in w around 0 5.0%
expm1-udef89.3%
log1p-udef89.3%
add-exp-log89.3%
+-commutative89.3%
Applied egg-rr89.3%
Final simplification97.6%
(FPCore (w l) :precision binary64 (if (<= w -440.0) (/ l 0.0) (if (<= w 4.7e-19) l (+ (+ l 1.0) -1.0))))
double code(double w, double l) {
double tmp;
if (w <= -440.0) {
tmp = l / 0.0;
} else if (w <= 4.7e-19) {
tmp = l;
} else {
tmp = (l + 1.0) + -1.0;
}
return tmp;
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
real(8) :: tmp
if (w <= (-440.0d0)) then
tmp = l / 0.0d0
else if (w <= 4.7d-19) then
tmp = l
else
tmp = (l + 1.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double w, double l) {
double tmp;
if (w <= -440.0) {
tmp = l / 0.0;
} else if (w <= 4.7e-19) {
tmp = l;
} else {
tmp = (l + 1.0) + -1.0;
}
return tmp;
}
def code(w, l): tmp = 0 if w <= -440.0: tmp = l / 0.0 elif w <= 4.7e-19: tmp = l else: tmp = (l + 1.0) + -1.0 return tmp
function code(w, l) tmp = 0.0 if (w <= -440.0) tmp = Float64(l / 0.0); elseif (w <= 4.7e-19) tmp = l; else tmp = Float64(Float64(l + 1.0) + -1.0); end return tmp end
function tmp_2 = code(w, l) tmp = 0.0; if (w <= -440.0) tmp = l / 0.0; elseif (w <= 4.7e-19) tmp = l; else tmp = (l + 1.0) + -1.0; end tmp_2 = tmp; end
code[w_, l_] := If[LessEqual[w, -440.0], N[(l / 0.0), $MachinePrecision], If[LessEqual[w, 4.7e-19], l, N[(N[(l + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;w \leq -440:\\
\;\;\;\;\frac{\ell}{0}\\
\mathbf{elif}\;w \leq 4.7 \cdot 10^{-19}:\\
\;\;\;\;\ell\\
\mathbf{else}:\\
\;\;\;\;\left(\ell + 1\right) + -1\\
\end{array}
\end{array}
if w < -440Initial program 100.0%
exp-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
Simplified100.0%
*-un-lft-identity100.0%
add-cube-cbrt100.0%
times-frac100.0%
cbrt-unprod100.0%
prod-exp100.0%
Applied egg-rr100.0%
associate-*l/100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in w around 0 100.0%
Taylor expanded in w around 0 3.7%
Simplified100.0%
if -440 < w < 4.7e-19Initial program 99.8%
exp-neg99.8%
associate-*l/99.8%
*-lft-identity99.8%
Simplified99.8%
Taylor expanded in w around 0 98.8%
if 4.7e-19 < w Initial program 97.5%
exp-neg97.5%
associate-*l/97.5%
*-lft-identity97.5%
Simplified97.5%
expm1-log1p-u97.4%
Applied egg-rr97.4%
Taylor expanded in w around 0 7.6%
expm1-udef88.2%
log1p-udef88.2%
add-exp-log88.4%
+-commutative88.4%
Applied egg-rr88.4%
Final simplification97.2%
(FPCore (w l) :precision binary64 (if (<= w -310.0) (/ l 0.0) l))
double code(double w, double l) {
double tmp;
if (w <= -310.0) {
tmp = l / 0.0;
} else {
tmp = l;
}
return tmp;
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
real(8) :: tmp
if (w <= (-310.0d0)) then
tmp = l / 0.0d0
else
tmp = l
end if
code = tmp
end function
public static double code(double w, double l) {
double tmp;
if (w <= -310.0) {
tmp = l / 0.0;
} else {
tmp = l;
}
return tmp;
}
def code(w, l): tmp = 0 if w <= -310.0: tmp = l / 0.0 else: tmp = l return tmp
function code(w, l) tmp = 0.0 if (w <= -310.0) tmp = Float64(l / 0.0); else tmp = l; end return tmp end
function tmp_2 = code(w, l) tmp = 0.0; if (w <= -310.0) tmp = l / 0.0; else tmp = l; end tmp_2 = tmp; end
code[w_, l_] := If[LessEqual[w, -310.0], N[(l / 0.0), $MachinePrecision], l]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;w \leq -310:\\
\;\;\;\;\frac{\ell}{0}\\
\mathbf{else}:\\
\;\;\;\;\ell\\
\end{array}
\end{array}
if w < -310Initial program 100.0%
exp-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
Simplified100.0%
*-un-lft-identity100.0%
add-cube-cbrt100.0%
times-frac100.0%
cbrt-unprod100.0%
prod-exp100.0%
Applied egg-rr100.0%
associate-*l/100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in w around 0 100.0%
Taylor expanded in w around 0 3.7%
Simplified100.0%
if -310 < w Initial program 99.3%
exp-neg99.3%
associate-*l/99.3%
*-lft-identity99.3%
Simplified99.3%
Taylor expanded in w around 0 76.2%
Final simplification82.4%
(FPCore (w l) :precision binary64 l)
double code(double w, double l) {
return l;
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
code = l
end function
public static double code(double w, double l) {
return l;
}
def code(w, l): return l
function code(w, l) return l end
function tmp = code(w, l) tmp = l; end
code[w_, l_] := l
\begin{array}{l}
\\
\ell
\end{array}
Initial program 99.5%
exp-neg99.5%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Taylor expanded in w around 0 57.2%
Final simplification57.2%
herbie shell --seed 2023230
(FPCore (w l)
:name "exp-w (used to crash)"
:precision binary64
(* (exp (- w)) (pow l (exp w))))