
(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
(let* ((t_0 (sqrt (cos x))) (t_1 (cbrt (exp t_0))) (t_2 (exp (- x))))
(if (<= (* (fmod (exp x) t_0) t_2) 2.0)
(/ (fmod (exp x) (+ (log (pow t_1 2.0)) (log t_1))) (exp x))
t_2)))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = cbrt(exp(t_0));
double t_2 = exp(-x);
double tmp;
if ((fmod(exp(x), t_0) * t_2) <= 2.0) {
tmp = fmod(exp(x), (log(pow(t_1, 2.0)) + log(t_1))) / exp(x);
} else {
tmp = t_2;
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) t_1 = cbrt(exp(t_0)) t_2 = exp(Float64(-x)) tmp = 0.0 if (Float64(rem(exp(x), t_0) * t_2) <= 2.0) tmp = Float64(rem(exp(x), Float64(log((t_1 ^ 2.0)) + log(t_1))) / exp(x)); else tmp = t_2; end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Exp[t$95$0], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$2 = 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$2), $MachinePrecision], 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Log[N[Power[t$95$1, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$1], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := \sqrt[3]{e^{t_0}}\\
t_2 := e^{-x}\\
\mathbf{if}\;\left(\left(e^{x}\right) \bmod t_0\right) \cdot t_2 \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\log \left({t_1}^{2}\right) + \log t_1\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 7.4%
/-rgt-identity7.4%
associate-/r/7.4%
exp-neg7.4%
remove-double-neg7.4%
Simplified7.4%
add-log-exp7.4%
add-cube-cbrt56.1%
log-prod56.1%
pow256.1%
Applied egg-rr56.1%
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-exp-log0.0%
div-exp0.1%
Applied egg-rr0.1%
Taylor expanded in x around inf 98.0%
neg-mul-198.0%
Simplified98.0%
Final simplification64.0%
(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.0%
/-rgt-identity6.0%
associate-/r/6.0%
exp-neg6.0%
remove-double-neg6.0%
Simplified6.0%
add-exp-log6.0%
div-exp6.0%
Applied egg-rr6.0%
Taylor expanded in x around inf 62.4%
neg-mul-162.4%
Simplified62.4%
Final simplification62.4%
herbie shell --seed 2023338
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))