
(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))))
(if (<= (* (fmod (exp x) t_0) (exp (- x))) 2.0)
(/
(fmod (exp x) (+ (* t_0 0.6666666666666666) (log (cbrt (exp t_0)))))
(exp x))
(exp (* (* x -0.3333333333333333) 3.0)))))
double code(double x) {
double t_0 = sqrt(cos(x));
double tmp;
if ((fmod(exp(x), t_0) * exp(-x)) <= 2.0) {
tmp = fmod(exp(x), ((t_0 * 0.6666666666666666) + log(cbrt(exp(t_0))))) / exp(x);
} else {
tmp = exp(((x * -0.3333333333333333) * 3.0));
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) tmp = 0.0 if (Float64(rem(exp(x), t_0) * exp(Float64(-x))) <= 2.0) tmp = Float64(rem(exp(x), Float64(Float64(t_0 * 0.6666666666666666) + log(cbrt(exp(t_0))))) / exp(x)); else tmp = exp(Float64(Float64(x * -0.3333333333333333) * 3.0)); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $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], N[Exp[N[(N[(x * -0.3333333333333333), $MachinePrecision] * 3.0), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
\mathbf{if}\;\left(\left(e^{x}\right) \bmod t\_0\right) \cdot e^{-x} \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}:\\
\;\;\;\;e^{\left(x \cdot -0.3333333333333333\right) \cdot 3}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.3%
/-rgt-identity9.3%
associate-/r/9.3%
exp-neg9.3%
remove-double-neg9.3%
Simplified9.3%
add-log-exp9.3%
add-cube-cbrt48.0%
log-prod48.0%
pow248.0%
Applied egg-rr48.0%
unpow248.0%
log-prod48.0%
pow1/348.0%
log-pow48.1%
add-log-exp48.1%
pow1/348.1%
log-pow48.1%
add-log-exp48.1%
Applied egg-rr48.1%
distribute-rgt-out48.1%
metadata-eval48.1%
Simplified48.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-cube-cbrt0.0%
pow30.0%
pow-to-exp0.0%
pow1/30.0%
log-pow0.0%
log-div0.0%
add-log-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (if (<= (* (fmod (exp x) (sqrt (cos x))) (exp (- x))) 2.0) (/ (fmod (exp x) (+ 0.6666666666666666 (log (cbrt E)))) (exp x)) (exp (* (* x -0.3333333333333333) 3.0))))
double code(double x) {
double tmp;
if ((fmod(exp(x), sqrt(cos(x))) * exp(-x)) <= 2.0) {
tmp = fmod(exp(x), (0.6666666666666666 + log(cbrt(((double) M_E))))) / exp(x);
} else {
tmp = exp(((x * -0.3333333333333333) * 3.0));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) <= 2.0) tmp = Float64(rem(exp(x), Float64(0.6666666666666666 + log(cbrt(exp(1))))) / exp(x)); else tmp = exp(Float64(Float64(x * -0.3333333333333333) * 3.0)); end return tmp end
code[x_] := If[LessEqual[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], 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(0.6666666666666666 + N[Log[N[Power[E, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[(x * -0.3333333333333333), $MachinePrecision] * 3.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(0.6666666666666666 + \log \left(\sqrt[3]{e}\right)\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{\left(x \cdot -0.3333333333333333\right) \cdot 3}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.3%
/-rgt-identity9.3%
associate-/r/9.3%
exp-neg9.3%
remove-double-neg9.3%
Simplified9.3%
add-log-exp9.3%
add-cube-cbrt48.0%
log-prod48.0%
pow248.0%
Applied egg-rr48.0%
unpow248.0%
log-prod48.0%
pow1/348.0%
log-pow48.1%
add-log-exp48.1%
pow1/348.1%
log-pow48.1%
add-log-exp48.1%
Applied egg-rr48.1%
distribute-rgt-out48.1%
metadata-eval48.1%
Simplified48.1%
Taylor expanded in x around 0 47.5%
exp-1-e47.5%
Simplified47.5%
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-cube-cbrt0.0%
pow30.0%
pow-to-exp0.0%
pow1/30.0%
log-pow0.0%
log-div0.0%
add-log-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (if (<= x -2e-16) (/ (fmod (exp x) 1.0) (exp x)) (exp (* (* x -0.3333333333333333) 3.0))))
double code(double x) {
double tmp;
if (x <= -2e-16) {
tmp = fmod(exp(x), 1.0) / exp(x);
} else {
tmp = exp(((x * -0.3333333333333333) * 3.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-16)) then
tmp = mod(exp(x), 1.0d0) / exp(x)
else
tmp = exp(((x * (-0.3333333333333333d0)) * 3.0d0))
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-16: tmp = math.fmod(math.exp(x), 1.0) / math.exp(x) else: tmp = math.exp(((x * -0.3333333333333333) * 3.0)) return tmp
function code(x) tmp = 0.0 if (x <= -2e-16) tmp = Float64(rem(exp(x), 1.0) / exp(x)); else tmp = exp(Float64(Float64(x * -0.3333333333333333) * 3.0)); end return tmp end
code[x_] := If[LessEqual[x, -2e-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[N[(N[(x * -0.3333333333333333), $MachinePrecision] * 3.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-16}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{\left(x \cdot -0.3333333333333333\right) \cdot 3}\\
\end{array}
\end{array}
if x < -2e-16Initial program 99.8%
/-rgt-identity99.8%
associate-/r/100.0%
exp-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
if -2e-16 < x Initial program 4.5%
/-rgt-identity4.5%
associate-/r/4.5%
exp-neg4.5%
remove-double-neg4.5%
Simplified4.5%
add-cube-cbrt4.5%
pow34.5%
pow-to-exp4.5%
pow1/34.5%
log-pow4.5%
log-div4.5%
add-log-exp4.5%
Applied egg-rr4.5%
Taylor expanded in x around inf 55.8%
*-commutative55.8%
Simplified55.8%
(FPCore (x) :precision binary64 (exp (* (* x -0.3333333333333333) 3.0)))
double code(double x) {
return exp(((x * -0.3333333333333333) * 3.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(((x * (-0.3333333333333333d0)) * 3.0d0))
end function
public static double code(double x) {
return Math.exp(((x * -0.3333333333333333) * 3.0));
}
def code(x): return math.exp(((x * -0.3333333333333333) * 3.0))
function code(x) return exp(Float64(Float64(x * -0.3333333333333333) * 3.0)) end
function tmp = code(x) tmp = exp(((x * -0.3333333333333333) * 3.0)); end
code[x_] := N[Exp[N[(N[(x * -0.3333333333333333), $MachinePrecision] * 3.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(x \cdot -0.3333333333333333\right) \cdot 3}
\end{array}
Initial program 7.5%
/-rgt-identity7.5%
associate-/r/7.5%
exp-neg7.5%
remove-double-neg7.5%
Simplified7.5%
add-cube-cbrt7.5%
pow37.5%
pow-to-exp7.5%
pow1/37.5%
log-pow7.5%
log-div7.5%
add-log-exp7.5%
Applied egg-rr7.5%
Taylor expanded in x around inf 55.1%
*-commutative55.1%
Simplified55.1%
herbie shell --seed 2024101
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))