
(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 2 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 (if (<= x 0.1) (/ (fmod (exp x) (* 3.0 (log (cbrt (exp (sqrt (cos x))))))) (exp x)) (exp (- x))))
double code(double x) {
double tmp;
if (x <= 0.1) {
tmp = fmod(exp(x), (3.0 * log(cbrt(exp(sqrt(cos(x))))))) / exp(x);
} else {
tmp = exp(-x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 0.1) tmp = Float64(rem(exp(x), Float64(3.0 * log(cbrt(exp(sqrt(cos(x))))))) / exp(x)); else tmp = exp(Float64(-x)); end return tmp end
code[x_] := If[LessEqual[x, 0.1], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(3.0 * N[Log[N[Power[N[Exp[N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, 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 0.1:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(3 \cdot \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < 0.10000000000000001Initial program 7.5%
/-rgt-identity7.5%
1-exp7.5%
associate-/l*7.5%
exp-diff7.5%
neg-sub07.5%
remove-double-neg7.5%
Simplified7.5%
add-log-exp7.5%
add-cube-cbrt53.8%
log-prod53.8%
pow253.8%
Applied egg-rr53.8%
log-pow53.8%
distribute-lft1-in53.8%
metadata-eval53.8%
Simplified53.8%
if 0.10000000000000001 < x Initial program 0.0%
/-rgt-identity0.0%
1-exp0.0%
associate-/l*0.0%
exp-diff0.0%
neg-sub00.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.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
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 6.1%
/-rgt-identity6.1%
1-exp6.1%
associate-/l*6.1%
exp-diff6.1%
neg-sub06.1%
remove-double-neg6.1%
Simplified6.1%
add-cbrt-cube6.1%
pow1/36.1%
pow-to-exp6.1%
pow36.1%
log-pow6.1%
log-div6.1%
add-log-exp6.1%
Applied egg-rr6.1%
Taylor expanded in x around inf 60.9%
neg-mul-160.9%
Simplified60.9%
Final simplification60.9%
herbie shell --seed 2024034
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))