
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
double code(double x) {
return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
function code(x) return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
double code(double x) {
return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
function code(x) return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))) (t_1 (exp (- x))))
(if (<= (* (fmod (exp x) t_0) t_1) 2.0)
(/ (fmod (exp x) (* 3.0 (log (cbrt (exp t_0))))) (exp x))
t_1)))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = exp(-x);
double tmp;
if ((fmod(exp(x), t_0) * t_1) <= 2.0) {
tmp = fmod(exp(x), (3.0 * log(cbrt(exp(t_0))))) / exp(x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) t_1 = exp(Float64(-x)) tmp = 0.0 if (Float64(rem(exp(x), t_0) * t_1) <= 2.0) tmp = Float64(rem(exp(x), Float64(3.0 * log(cbrt(exp(t_0))))) / exp(x)); else tmp = t_1; end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$1), $MachinePrecision], 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(3.0 * N[Log[N[Power[N[Exp[t$95$0], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := e^{-x}\\
\mathbf{if}\;\left(\left(e^{x}\right) \bmod t\_0\right) \cdot t\_1 \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(3 \cdot \log \left(\sqrt[3]{e^{t\_0}}\right)\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.4%
/-rgt-identity9.4%
associate-/r/9.4%
exp-neg9.5%
remove-double-neg9.5%
Simplified9.5%
add-log-exp9.5%
add-cube-cbrt55.2%
log-prod55.3%
pow255.3%
Applied egg-rr55.3%
log-pow55.3%
distribute-lft1-in55.3%
metadata-eval55.3%
Simplified55.3%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 0.0%
/-rgt-identity0.0%
associate-/r/0.0%
exp-neg0.0%
remove-double-neg0.0%
Simplified0.0%
add-cbrt-cube0.0%
pow1/30.0%
pow-to-exp0.0%
pow30.0%
log-pow0.0%
log-div0.0%
add-log-exp0.1%
Applied egg-rr0.1%
Taylor expanded in x around inf 96.3%
neg-mul-196.3%
Simplified96.3%
Final simplification63.8%
(FPCore (x) :precision binary64 (if (<= x -1e-16) (exp (- (log (fmod (exp x) 1.0)) x)) (exp (- x))))
double code(double x) {
double tmp;
if (x <= -1e-16) {
tmp = exp((log(fmod(exp(x), 1.0)) - x));
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1d-16)) then
tmp = exp((log(mod(exp(x), 1.0d0)) - x))
else
tmp = exp(-x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -1e-16: tmp = math.exp((math.log(math.fmod(math.exp(x), 1.0)) - x)) else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if (x <= -1e-16) tmp = exp(Float64(log(rem(exp(x), 1.0)) - x)); else tmp = exp(Float64(-x)); end return tmp end
code[x_] := If[LessEqual[x, -1e-16], N[Exp[N[(N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision], N[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-16}:\\
\;\;\;\;e^{\log \left(\left(e^{x}\right) \bmod 1\right) - x}\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -9.9999999999999998e-17Initial program 77.3%
/-rgt-identity77.3%
associate-/r/77.1%
exp-neg77.8%
remove-double-neg77.8%
Simplified77.8%
Taylor expanded in x around 0 77.8%
add-exp-log77.8%
div-exp78.5%
Applied egg-rr78.5%
if -9.9999999999999998e-17 < x Initial program 5.0%
/-rgt-identity5.0%
associate-/r/5.0%
exp-neg5.0%
remove-double-neg5.0%
Simplified5.0%
add-cbrt-cube5.0%
pow1/34.9%
pow-to-exp4.9%
pow34.9%
log-pow4.9%
log-div4.9%
add-log-exp4.9%
Applied egg-rr4.9%
Taylor expanded in x around inf 62.1%
neg-mul-162.1%
Simplified62.1%
Final simplification62.7%
(FPCore (x) :precision binary64 (if (<= x -1e-16) (/ (fmod (exp x) 1.0) (exp x)) (exp (- x))))
double code(double x) {
double tmp;
if (x <= -1e-16) {
tmp = fmod(exp(x), 1.0) / exp(x);
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1d-16)) then
tmp = mod(exp(x), 1.0d0) / exp(x)
else
tmp = exp(-x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -1e-16: tmp = math.fmod(math.exp(x), 1.0) / math.exp(x) else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if (x <= -1e-16) tmp = Float64(rem(exp(x), 1.0) / exp(x)); else tmp = exp(Float64(-x)); end return tmp end
code[x_] := If[LessEqual[x, -1e-16], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-16}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -9.9999999999999998e-17Initial program 77.3%
/-rgt-identity77.3%
associate-/r/77.1%
exp-neg77.8%
remove-double-neg77.8%
Simplified77.8%
Taylor expanded in x around 0 77.8%
if -9.9999999999999998e-17 < x Initial program 5.0%
/-rgt-identity5.0%
associate-/r/5.0%
exp-neg5.0%
remove-double-neg5.0%
Simplified5.0%
add-cbrt-cube5.0%
pow1/34.9%
pow-to-exp4.9%
pow34.9%
log-pow4.9%
log-div4.9%
add-log-exp4.9%
Applied egg-rr4.9%
Taylor expanded in x around inf 62.1%
neg-mul-162.1%
Simplified62.1%
Final simplification62.6%
(FPCore (x) :precision binary64 (exp (- x)))
double code(double x) {
return exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(-x)
end function
public static double code(double x) {
return Math.exp(-x);
}
def code(x): return math.exp(-x)
function code(x) return exp(Float64(-x)) end
function tmp = code(x) tmp = exp(-x); end
code[x_] := N[Exp[(-x)], $MachinePrecision]
\begin{array}{l}
\\
e^{-x}
\end{array}
Initial program 7.5%
/-rgt-identity7.5%
associate-/r/7.5%
exp-neg7.5%
remove-double-neg7.5%
Simplified7.5%
add-cbrt-cube7.5%
pow1/37.5%
pow-to-exp7.5%
pow37.5%
log-pow7.5%
log-div7.5%
add-log-exp7.5%
Applied egg-rr7.5%
Taylor expanded in x around inf 61.0%
neg-mul-161.0%
Simplified61.0%
Final simplification61.0%
herbie shell --seed 2024041
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))