
(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 3 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 (cbrt (exp (cos x)))) (t_1 (exp (- x))))
(if (<= (* (fmod (exp x) (sqrt (cos x))) t_1) 2.0)
(/ (fmod (exp x) (sqrt (+ (log (pow t_0 2.0)) (log t_0)))) (exp x))
t_1)))
double code(double x) {
double t_0 = cbrt(exp(cos(x)));
double t_1 = exp(-x);
double tmp;
if ((fmod(exp(x), sqrt(cos(x))) * t_1) <= 2.0) {
tmp = fmod(exp(x), sqrt((log(pow(t_0, 2.0)) + log(t_0)))) / exp(x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x) t_0 = cbrt(exp(cos(x))) t_1 = exp(Float64(-x)) tmp = 0.0 if (Float64(rem(exp(x), sqrt(cos(x))) * t_1) <= 2.0) tmp = Float64(rem(exp(x), sqrt(Float64(log((t_0 ^ 2.0)) + log(t_0)))) / exp(x)); else tmp = t_1; end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[Exp[N[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-x)], $MachinePrecision]}, 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] * t$95$1), $MachinePrecision], 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[(N[Log[N[Power[t$95$0, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$0], $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[3]{e^{\cos x}}\\
t_1 := e^{-x}\\
\mathbf{if}\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot t\_1 \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\log \left({t\_0}^{2}\right) + \log t\_0}\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 7.3%
/-rgt-identity7.3%
associate-/r/7.3%
exp-neg7.3%
remove-double-neg7.3%
Simplified7.3%
add-log-exp7.3%
add-cube-cbrt60.4%
log-prod60.3%
pow260.3%
Applied egg-rr60.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-exp-log0.0%
*-un-lft-identity0.0%
exp-prod0.0%
log-div0.0%
add-log-exp0.1%
Applied egg-rr0.1%
Taylor expanded in x around inf 98.2%
neg-mul-198.2%
Simplified98.2%
Taylor expanded in x around inf 98.2%
mul-1-neg98.2%
Simplified98.2%
(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 5.7%
/-rgt-identity5.7%
associate-/r/5.7%
exp-neg5.7%
remove-double-neg5.7%
Simplified5.7%
add-exp-log5.7%
*-un-lft-identity5.7%
exp-prod5.7%
log-div5.7%
add-log-exp5.8%
Applied egg-rr5.8%
Taylor expanded in x around inf 66.8%
neg-mul-166.8%
Simplified66.8%
Taylor expanded in x around inf 66.8%
mul-1-neg66.8%
Simplified66.8%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 5.7%
/-rgt-identity5.7%
associate-/r/5.7%
exp-neg5.7%
remove-double-neg5.7%
Simplified5.7%
add-exp-log5.7%
*-un-lft-identity5.7%
exp-prod5.7%
log-div5.7%
add-log-exp5.8%
Applied egg-rr5.8%
Taylor expanded in x around inf 66.8%
neg-mul-166.8%
Simplified66.8%
Taylor expanded in x around 0 47.4%
herbie shell --seed 2024137
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))