
(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 (let* ((t_0 (* w (+ (log l) -1.0)))) (if (<= w -0.22) (exp (- w)) (if (<= w 0.48) (+ l (* l t_0)) (exp t_0)))))
double code(double w, double l) {
double t_0 = w * (log(l) + -1.0);
double tmp;
if (w <= -0.22) {
tmp = exp(-w);
} else if (w <= 0.48) {
tmp = l + (l * t_0);
} else {
tmp = exp(t_0);
}
return tmp;
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
real(8) :: t_0
real(8) :: tmp
t_0 = w * (log(l) + (-1.0d0))
if (w <= (-0.22d0)) then
tmp = exp(-w)
else if (w <= 0.48d0) then
tmp = l + (l * t_0)
else
tmp = exp(t_0)
end if
code = tmp
end function
public static double code(double w, double l) {
double t_0 = w * (Math.log(l) + -1.0);
double tmp;
if (w <= -0.22) {
tmp = Math.exp(-w);
} else if (w <= 0.48) {
tmp = l + (l * t_0);
} else {
tmp = Math.exp(t_0);
}
return tmp;
}
def code(w, l): t_0 = w * (math.log(l) + -1.0) tmp = 0 if w <= -0.22: tmp = math.exp(-w) elif w <= 0.48: tmp = l + (l * t_0) else: tmp = math.exp(t_0) return tmp
function code(w, l) t_0 = Float64(w * Float64(log(l) + -1.0)) tmp = 0.0 if (w <= -0.22) tmp = exp(Float64(-w)); elseif (w <= 0.48) tmp = Float64(l + Float64(l * t_0)); else tmp = exp(t_0); end return tmp end
function tmp_2 = code(w, l) t_0 = w * (log(l) + -1.0); tmp = 0.0; if (w <= -0.22) tmp = exp(-w); elseif (w <= 0.48) tmp = l + (l * t_0); else tmp = exp(t_0); end tmp_2 = tmp; end
code[w_, l_] := Block[{t$95$0 = N[(w * N[(N[Log[l], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[w, -0.22], N[Exp[(-w)], $MachinePrecision], If[LessEqual[w, 0.48], N[(l + N[(l * t$95$0), $MachinePrecision]), $MachinePrecision], N[Exp[t$95$0], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := w \cdot \left(\log \ell + -1\right)\\
\mathbf{if}\;w \leq -0.22:\\
\;\;\;\;e^{-w}\\
\mathbf{elif}\;w \leq 0.48:\\
\;\;\;\;\ell + \ell \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;e^{t\_0}\\
\end{array}
\end{array}
if w < -0.220000000000000001Initial program 100.0%
exp-neg100.0%
remove-double-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in l around inf 100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
log-rec100.0%
remove-double-neg100.0%
+-rgt-identity100.0%
exp-diff100.0%
+-rgt-identity100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
Simplified100.0%
Taylor expanded in w around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
if -0.220000000000000001 < w < 0.47999999999999998Initial program 99.4%
exp-neg99.4%
remove-double-neg99.4%
associate-*l/99.4%
*-lft-identity99.4%
remove-double-neg99.4%
Simplified99.4%
Taylor expanded in w around 0 98.2%
+-commutative98.2%
fma-define98.2%
sub-neg98.2%
*-commutative98.2%
neg-mul-198.2%
distribute-rgt-out98.2%
Simplified98.2%
Taylor expanded in w around 0 98.2%
if 0.47999999999999998 < w Initial program 95.7%
exp-neg95.7%
remove-double-neg95.7%
associate-*l/95.7%
*-lft-identity95.7%
remove-double-neg95.7%
Simplified95.7%
Taylor expanded in l around inf 95.7%
mul-1-neg95.7%
distribute-rgt-neg-in95.7%
log-rec95.7%
remove-double-neg95.7%
+-rgt-identity95.7%
exp-diff100.0%
+-rgt-identity100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
Simplified100.0%
Taylor expanded in w around 0 100.0%
distribute-rgt1-in100.0%
Simplified100.0%
Taylor expanded in w around inf 100.0%
Final simplification99.1%
(FPCore (w l) :precision binary64 (/ (pow (pow l (sqrt (exp w))) (exp (* w 0.5))) (exp w)))
double code(double w, double l) {
return pow(pow(l, sqrt(exp(w))), exp((w * 0.5))) / exp(w);
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
code = ((l ** sqrt(exp(w))) ** exp((w * 0.5d0))) / exp(w)
end function
public static double code(double w, double l) {
return Math.pow(Math.pow(l, Math.sqrt(Math.exp(w))), Math.exp((w * 0.5))) / Math.exp(w);
}
def code(w, l): return math.pow(math.pow(l, math.sqrt(math.exp(w))), math.exp((w * 0.5))) / math.exp(w)
function code(w, l) return Float64(((l ^ sqrt(exp(w))) ^ exp(Float64(w * 0.5))) / exp(w)) end
function tmp = code(w, l) tmp = ((l ^ sqrt(exp(w))) ^ exp((w * 0.5))) / exp(w); end
code[w_, l_] := N[(N[Power[N[Power[l, N[Sqrt[N[Exp[w], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], N[Exp[N[(w * 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Exp[w], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left({\ell}^{\left(\sqrt{e^{w}}\right)}\right)}^{\left(e^{w \cdot 0.5}\right)}}{e^{w}}
\end{array}
Initial program 98.9%
exp-neg98.9%
remove-double-neg98.9%
associate-*l/98.9%
*-lft-identity98.9%
remove-double-neg98.9%
Simplified98.9%
add-sqr-sqrt98.9%
pow-unpow98.9%
pow-to-exp94.6%
Applied egg-rr94.6%
exp-to-pow98.9%
Simplified98.9%
pow1/298.9%
pow-exp98.9%
Applied egg-rr98.9%
(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 98.9%
exp-neg98.9%
remove-double-neg98.9%
associate-*l/98.9%
*-lft-identity98.9%
remove-double-neg98.9%
Simplified98.9%
(FPCore (w l) :precision binary64 (if (<= w -52000000.0) (exp (- w)) (/ (+ l (* (* l w) (log l))) (exp w))))
double code(double w, double l) {
double tmp;
if (w <= -52000000.0) {
tmp = exp(-w);
} else {
tmp = (l + ((l * w) * log(l))) / exp(w);
}
return tmp;
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
real(8) :: tmp
if (w <= (-52000000.0d0)) then
tmp = exp(-w)
else
tmp = (l + ((l * w) * log(l))) / exp(w)
end if
code = tmp
end function
public static double code(double w, double l) {
double tmp;
if (w <= -52000000.0) {
tmp = Math.exp(-w);
} else {
tmp = (l + ((l * w) * Math.log(l))) / Math.exp(w);
}
return tmp;
}
def code(w, l): tmp = 0 if w <= -52000000.0: tmp = math.exp(-w) else: tmp = (l + ((l * w) * math.log(l))) / math.exp(w) return tmp
function code(w, l) tmp = 0.0 if (w <= -52000000.0) tmp = exp(Float64(-w)); else tmp = Float64(Float64(l + Float64(Float64(l * w) * log(l))) / exp(w)); end return tmp end
function tmp_2 = code(w, l) tmp = 0.0; if (w <= -52000000.0) tmp = exp(-w); else tmp = (l + ((l * w) * log(l))) / exp(w); end tmp_2 = tmp; end
code[w_, l_] := If[LessEqual[w, -52000000.0], N[Exp[(-w)], $MachinePrecision], N[(N[(l + N[(N[(l * w), $MachinePrecision] * N[Log[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Exp[w], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;w \leq -52000000:\\
\;\;\;\;e^{-w}\\
\mathbf{else}:\\
\;\;\;\;\frac{\ell + \left(\ell \cdot w\right) \cdot \log \ell}{e^{w}}\\
\end{array}
\end{array}
if w < -5.2e7Initial program 100.0%
exp-neg100.0%
remove-double-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in l around inf 100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
log-rec100.0%
remove-double-neg100.0%
+-rgt-identity100.0%
exp-diff100.0%
+-rgt-identity100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
Simplified100.0%
Taylor expanded in w around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
if -5.2e7 < w Initial program 98.4%
exp-neg98.4%
remove-double-neg98.4%
associate-*l/98.4%
*-lft-identity98.4%
remove-double-neg98.4%
Simplified98.4%
Taylor expanded in w around 0 97.0%
associate-*r*97.5%
Simplified97.5%
(FPCore (w l) :precision binary64 (if (<= w -52000000.0) (exp (- w)) (/ (pow l (+ w 1.0)) (exp w))))
double code(double w, double l) {
double tmp;
if (w <= -52000000.0) {
tmp = exp(-w);
} else {
tmp = pow(l, (w + 1.0)) / exp(w);
}
return tmp;
}
real(8) function code(w, l)
real(8), intent (in) :: w
real(8), intent (in) :: l
real(8) :: tmp
if (w <= (-52000000.0d0)) then
tmp = exp(-w)
else
tmp = (l ** (w + 1.0d0)) / exp(w)
end if
code = tmp
end function
public static double code(double w, double l) {
double tmp;
if (w <= -52000000.0) {
tmp = Math.exp(-w);
} else {
tmp = Math.pow(l, (w + 1.0)) / Math.exp(w);
}
return tmp;
}
def code(w, l): tmp = 0 if w <= -52000000.0: tmp = math.exp(-w) else: tmp = math.pow(l, (w + 1.0)) / math.exp(w) return tmp
function code(w, l) tmp = 0.0 if (w <= -52000000.0) tmp = exp(Float64(-w)); else tmp = Float64((l ^ Float64(w + 1.0)) / exp(w)); end return tmp end
function tmp_2 = code(w, l) tmp = 0.0; if (w <= -52000000.0) tmp = exp(-w); else tmp = (l ^ (w + 1.0)) / exp(w); end tmp_2 = tmp; end
code[w_, l_] := If[LessEqual[w, -52000000.0], N[Exp[(-w)], $MachinePrecision], N[(N[Power[l, N[(w + 1.0), $MachinePrecision]], $MachinePrecision] / N[Exp[w], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;w \leq -52000000:\\
\;\;\;\;e^{-w}\\
\mathbf{else}:\\
\;\;\;\;\frac{{\ell}^{\left(w + 1\right)}}{e^{w}}\\
\end{array}
\end{array}
if w < -5.2e7Initial program 100.0%
exp-neg100.0%
remove-double-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in l around inf 100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
log-rec100.0%
remove-double-neg100.0%
+-rgt-identity100.0%
exp-diff100.0%
+-rgt-identity100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
Simplified100.0%
Taylor expanded in w around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
if -5.2e7 < w Initial program 98.4%
exp-neg98.4%
remove-double-neg98.4%
associate-*l/98.4%
*-lft-identity98.4%
remove-double-neg98.4%
Simplified98.4%
Taylor expanded in l around inf 92.0%
mul-1-neg92.0%
distribute-rgt-neg-in92.0%
log-rec92.0%
remove-double-neg92.0%
+-rgt-identity92.0%
exp-diff93.2%
+-rgt-identity93.2%
remove-double-neg93.2%
distribute-lft-neg-in93.2%
distribute-rgt-neg-out93.2%
Simplified93.2%
Taylor expanded in w around 0 92.3%
distribute-rgt1-in92.3%
Simplified92.3%
Taylor expanded in w around inf 92.3%
exp-diff91.1%
exp-to-pow97.5%
+-commutative97.5%
Simplified97.5%
(FPCore (w l) :precision binary64 (if (or (<= w -0.19) (not (<= w 3900000.0))) (exp (- w)) (+ l (* l (* w (+ (log l) -1.0))))))
double code(double w, double l) {
double tmp;
if ((w <= -0.19) || !(w <= 3900000.0)) {
tmp = exp(-w);
} else {
tmp = l + (l * (w * (log(l) + -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.19d0)) .or. (.not. (w <= 3900000.0d0))) then
tmp = exp(-w)
else
tmp = l + (l * (w * (log(l) + (-1.0d0))))
end if
code = tmp
end function
public static double code(double w, double l) {
double tmp;
if ((w <= -0.19) || !(w <= 3900000.0)) {
tmp = Math.exp(-w);
} else {
tmp = l + (l * (w * (Math.log(l) + -1.0)));
}
return tmp;
}
def code(w, l): tmp = 0 if (w <= -0.19) or not (w <= 3900000.0): tmp = math.exp(-w) else: tmp = l + (l * (w * (math.log(l) + -1.0))) return tmp
function code(w, l) tmp = 0.0 if ((w <= -0.19) || !(w <= 3900000.0)) tmp = exp(Float64(-w)); else tmp = Float64(l + Float64(l * Float64(w * Float64(log(l) + -1.0)))); end return tmp end
function tmp_2 = code(w, l) tmp = 0.0; if ((w <= -0.19) || ~((w <= 3900000.0))) tmp = exp(-w); else tmp = l + (l * (w * (log(l) + -1.0))); end tmp_2 = tmp; end
code[w_, l_] := If[Or[LessEqual[w, -0.19], N[Not[LessEqual[w, 3900000.0]], $MachinePrecision]], N[Exp[(-w)], $MachinePrecision], N[(l + N[(l * N[(w * N[(N[Log[l], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;w \leq -0.19 \lor \neg \left(w \leq 3900000\right):\\
\;\;\;\;e^{-w}\\
\mathbf{else}:\\
\;\;\;\;\ell + \ell \cdot \left(w \cdot \left(\log \ell + -1\right)\right)\\
\end{array}
\end{array}
if w < -0.19 or 3.9e6 < w Initial program 100.0%
exp-neg100.0%
remove-double-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in l around inf 100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
log-rec100.0%
remove-double-neg100.0%
+-rgt-identity100.0%
exp-diff100.0%
+-rgt-identity100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
Simplified100.0%
Taylor expanded in w around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
if -0.19 < w < 3.9e6Initial program 97.9%
exp-neg97.9%
remove-double-neg97.9%
associate-*l/97.9%
*-lft-identity97.9%
remove-double-neg97.9%
Simplified97.9%
Taylor expanded in w around 0 96.8%
+-commutative96.8%
fma-define96.8%
sub-neg96.8%
*-commutative96.8%
neg-mul-196.8%
distribute-rgt-out96.8%
Simplified96.8%
Taylor expanded in w around 0 96.8%
Final simplification98.4%
(FPCore (w l) :precision binary64 (if (or (<= w -0.7) (not (<= w 3900000.0))) (exp (- w)) l))
double code(double w, double l) {
double tmp;
if ((w <= -0.7) || !(w <= 3900000.0)) {
tmp = exp(-w);
} 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 <= (-0.7d0)) .or. (.not. (w <= 3900000.0d0))) then
tmp = exp(-w)
else
tmp = l
end if
code = tmp
end function
public static double code(double w, double l) {
double tmp;
if ((w <= -0.7) || !(w <= 3900000.0)) {
tmp = Math.exp(-w);
} else {
tmp = l;
}
return tmp;
}
def code(w, l): tmp = 0 if (w <= -0.7) or not (w <= 3900000.0): tmp = math.exp(-w) else: tmp = l return tmp
function code(w, l) tmp = 0.0 if ((w <= -0.7) || !(w <= 3900000.0)) tmp = exp(Float64(-w)); else tmp = l; end return tmp end
function tmp_2 = code(w, l) tmp = 0.0; if ((w <= -0.7) || ~((w <= 3900000.0))) tmp = exp(-w); else tmp = l; end tmp_2 = tmp; end
code[w_, l_] := If[Or[LessEqual[w, -0.7], N[Not[LessEqual[w, 3900000.0]], $MachinePrecision]], N[Exp[(-w)], $MachinePrecision], l]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;w \leq -0.7 \lor \neg \left(w \leq 3900000\right):\\
\;\;\;\;e^{-w}\\
\mathbf{else}:\\
\;\;\;\;\ell\\
\end{array}
\end{array}
if w < -0.69999999999999996 or 3.9e6 < w Initial program 100.0%
exp-neg100.0%
remove-double-neg100.0%
associate-*l/100.0%
*-lft-identity100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in l around inf 100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
log-rec100.0%
remove-double-neg100.0%
+-rgt-identity100.0%
exp-diff100.0%
+-rgt-identity100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
Simplified100.0%
Taylor expanded in w around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
if -0.69999999999999996 < w < 3.9e6Initial program 97.9%
exp-neg97.9%
remove-double-neg97.9%
associate-*l/97.9%
*-lft-identity97.9%
remove-double-neg97.9%
Simplified97.9%
Taylor expanded in w around 0 95.6%
Final simplification97.8%
(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 98.9%
exp-neg98.9%
remove-double-neg98.9%
associate-*l/98.9%
*-lft-identity98.9%
remove-double-neg98.9%
Simplified98.9%
Taylor expanded in w around 0 51.2%
herbie shell --seed 2024088
(FPCore (w l)
:name "exp-w (used to crash)"
:precision binary64
(* (exp (- w)) (pow l (exp w))))