
(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 5 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)) (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.9%
exp-neg99.9%
associate-*l/99.9%
*-lft-identity99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (w l) :precision binary64 (/ l (exp w)))
double code(double w, double l) {
return l / exp(w);
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
code = l / exp(w)
end function
public static double code(double w, double l) {
return l / Math.exp(w);
}
def code(w, l): return l / math.exp(w)
function code(w, l) return Float64(l / exp(w)) end
function tmp = code(w, l) tmp = l / exp(w); end
code[w_, l_] := N[(l / N[Exp[w], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\ell}{e^{w}}
\end{array}
Initial program 99.9%
exp-neg99.9%
associate-*l/99.9%
*-lft-identity99.9%
Simplified99.9%
Taylor expanded in w around 0 98.9%
Final simplification98.9%
(FPCore (w l) :precision binary64 (if (<= w -5.0) (/ (* l (+ l 2.0)) (+ l 2.0)) (if (<= w 0.055) l (+ (+ l 1.0) -1.0))))
double code(double w, double l) {
double tmp;
if (w <= -5.0) {
tmp = (l * (l + 2.0)) / (l + 2.0);
} else if (w <= 0.055) {
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 <= (-5.0d0)) then
tmp = (l * (l + 2.0d0)) / (l + 2.0d0)
else if (w <= 0.055d0) 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 <= -5.0) {
tmp = (l * (l + 2.0)) / (l + 2.0);
} else if (w <= 0.055) {
tmp = l;
} else {
tmp = (l + 1.0) + -1.0;
}
return tmp;
}
def code(w, l): tmp = 0 if w <= -5.0: tmp = (l * (l + 2.0)) / (l + 2.0) elif w <= 0.055: tmp = l else: tmp = (l + 1.0) + -1.0 return tmp
function code(w, l) tmp = 0.0 if (w <= -5.0) tmp = Float64(Float64(l * Float64(l + 2.0)) / Float64(l + 2.0)); elseif (w <= 0.055) 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 <= -5.0) tmp = (l * (l + 2.0)) / (l + 2.0); elseif (w <= 0.055) tmp = l; else tmp = (l + 1.0) + -1.0; end tmp_2 = tmp; end
code[w_, l_] := If[LessEqual[w, -5.0], N[(N[(l * N[(l + 2.0), $MachinePrecision]), $MachinePrecision] / N[(l + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[w, 0.055], l, N[(N[(l + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;w \leq -5:\\
\;\;\;\;\frac{\ell \cdot \left(\ell + 2\right)}{\ell + 2}\\
\mathbf{elif}\;w \leq 0.055:\\
\;\;\;\;\ell\\
\mathbf{else}:\\
\;\;\;\;\left(\ell + 1\right) + -1\\
\end{array}
\end{array}
if w < -5Initial program 100.0%
exp-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
Simplified100.0%
add-cube-cbrt100.0%
pow3100.0%
Applied egg-rr100.0%
Taylor expanded in w around 0 3.9%
unpow1/33.9%
rem-cube-cbrt3.9%
expm1-log1p-u3.9%
Applied egg-rr3.9%
expm1-udef3.6%
flip--28.5%
log1p-udef28.5%
rem-exp-log28.5%
+-commutative28.5%
log1p-udef28.5%
rem-exp-log28.5%
+-commutative28.5%
metadata-eval28.5%
log1p-udef28.5%
rem-exp-log28.5%
+-commutative28.5%
Applied egg-rr28.5%
difference-of-sqr-128.5%
associate-+l+28.5%
metadata-eval28.5%
associate--l+28.8%
metadata-eval28.8%
associate-+l+28.8%
metadata-eval28.8%
Simplified28.8%
if -5 < w < 0.0550000000000000003Initial program 99.7%
exp-neg99.7%
associate-*l/99.7%
*-lft-identity99.7%
Simplified99.7%
add-cube-cbrt97.7%
pow397.8%
add-sqr-sqrt97.2%
unpow-prod-down97.4%
Applied egg-rr97.4%
Taylor expanded in w around 0 98.6%
if 0.0550000000000000003 < w Initial program 100.0%
exp-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
Simplified100.0%
add-cube-cbrt100.0%
pow3100.0%
Applied egg-rr100.0%
Taylor expanded in w around 0 6.0%
unpow1/36.0%
rem-cube-cbrt6.0%
expm1-log1p-u6.0%
Applied egg-rr6.0%
expm1-udef87.5%
log1p-udef87.5%
rem-exp-log87.5%
+-commutative87.5%
Applied egg-rr87.5%
Final simplification73.8%
(FPCore (w l) :precision binary64 (if (<= w 0.053) l (+ (+ l 1.0) -1.0)))
double code(double w, double l) {
double tmp;
if (w <= 0.053) {
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 <= 0.053d0) 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 <= 0.053) {
tmp = l;
} else {
tmp = (l + 1.0) + -1.0;
}
return tmp;
}
def code(w, l): tmp = 0 if w <= 0.053: tmp = l else: tmp = (l + 1.0) + -1.0 return tmp
function code(w, l) tmp = 0.0 if (w <= 0.053) 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 <= 0.053) tmp = l; else tmp = (l + 1.0) + -1.0; end tmp_2 = tmp; end
code[w_, l_] := If[LessEqual[w, 0.053], l, N[(N[(l + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;w \leq 0.053:\\
\;\;\;\;\ell\\
\mathbf{else}:\\
\;\;\;\;\left(\ell + 1\right) + -1\\
\end{array}
\end{array}
if w < 0.0529999999999999985Initial program 99.8%
exp-neg99.8%
associate-*l/99.8%
*-lft-identity99.8%
Simplified99.8%
add-cube-cbrt98.6%
pow398.6%
add-sqr-sqrt98.3%
unpow-prod-down98.4%
Applied egg-rr98.4%
Taylor expanded in w around 0 62.4%
if 0.0529999999999999985 < w Initial program 100.0%
exp-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
Simplified100.0%
add-cube-cbrt100.0%
pow3100.0%
Applied egg-rr100.0%
Taylor expanded in w around 0 6.0%
unpow1/36.0%
rem-cube-cbrt6.0%
expm1-log1p-u6.0%
Applied egg-rr6.0%
expm1-udef87.5%
log1p-udef87.5%
rem-exp-log87.5%
+-commutative87.5%
Applied egg-rr87.5%
Final simplification65.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.9%
exp-neg99.9%
associate-*l/99.9%
*-lft-identity99.9%
Simplified99.9%
add-cube-cbrt98.8%
pow398.8%
add-sqr-sqrt98.5%
unpow-prod-down98.6%
Applied egg-rr98.6%
Taylor expanded in w around 0 55.5%
Final simplification55.5%
herbie shell --seed 2024027
(FPCore (w l)
:name "exp-w (used to crash)"
:precision binary64
(* (exp (- w)) (pow l (exp w))))