
(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 (exp (- x))))
(if (<= (* (fmod (exp x) t_0) t_1) 2.0)
(/
(fmod (exp x) (+ (* t_0 0.6666666666666666) (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), ((t_0 * 0.6666666666666666) + 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(Float64(t_0 * 0.6666666666666666) + 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[(N[(t$95$0 * 0.6666666666666666), $MachinePrecision] + 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(t\_0 \cdot 0.6666666666666666 + \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 8.1%
/-rgt-identity8.1%
associate-/r/8.1%
exp-neg8.1%
remove-double-neg8.1%
Simplified8.1%
add-log-exp8.1%
add-cube-cbrt55.8%
log-prod55.7%
pow255.7%
pow1/255.7%
pow1/255.7%
Applied egg-rr55.7%
unpow1/255.7%
unpow1/255.7%
Simplified55.7%
unpow255.7%
log-prod55.8%
pow1/355.8%
pow1/255.8%
metadata-eval55.8%
pow-pow55.8%
log-pow55.8%
add-log-exp55.8%
pow-pow55.8%
metadata-eval55.8%
pow1/355.9%
pow1/255.9%
metadata-eval55.9%
pow-pow55.9%
log-pow55.9%
Applied egg-rr55.9%
distribute-rgt-out55.9%
unpow1/255.9%
metadata-eval55.9%
Simplified55.9%
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%
Taylor expanded in x around 0 0.0%
+-commutative0.0%
fma-define0.0%
unpow20.0%
Simplified0.0%
add-exp-log0.0%
log-div0.0%
fma-undefine0.0%
+-commutative0.0%
associate-*r*0.0%
add-log-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
Simplified100.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.4%
/-rgt-identity6.4%
associate-/r/6.4%
exp-neg6.4%
remove-double-neg6.4%
Simplified6.4%
Taylor expanded in x around 0 5.8%
+-commutative5.8%
fma-define5.8%
unpow25.8%
Simplified5.8%
add-exp-log5.8%
log-div5.8%
fma-undefine5.8%
+-commutative5.8%
associate-*r*5.8%
add-log-exp5.8%
Applied egg-rr5.8%
Taylor expanded in x around inf 63.2%
mul-1-neg63.2%
Simplified63.2%
herbie shell --seed 2024097
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))