
(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 (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))
(pow E (- x)))))
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 = pow(((double) M_E), -x);
}
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(1) ^ Float64(-x); 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[Power[E, (-x)], $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\right)}\\
\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-cbrt58.6%
log-prod58.7%
pow258.7%
Applied egg-rr58.7%
unpow258.7%
log-prod58.7%
pow1/358.7%
log-pow58.7%
add-log-exp58.7%
pow1/358.7%
log-pow58.7%
add-log-exp58.7%
Applied egg-rr58.7%
distribute-rgt-out58.7%
metadata-eval58.7%
Simplified58.7%
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.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
Final simplification67.1%
(FPCore (x) :precision binary64 (fmod (exp x) 1.0))
double code(double x) {
return fmod(exp(x), 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), 1.0d0)
end function
def code(x): return math.fmod(math.exp(x), 1.0)
function code(x) return rem(exp(x), 1.0) end
code[x_] := N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod 1\right)
\end{array}
Initial program 5.8%
/-rgt-identity5.8%
associate-/r/5.8%
exp-neg5.8%
remove-double-neg5.8%
Simplified5.8%
Taylor expanded in x around 0 5.5%
Taylor expanded in x around 0 4.5%
Final simplification4.5%
(FPCore (x) :precision binary64 (pow E (- x)))
double code(double x) {
return pow(((double) M_E), -x);
}
public static double code(double x) {
return Math.pow(Math.E, -x);
}
def code(x): return math.pow(math.e, -x)
function code(x) return exp(1) ^ Float64(-x) end
function tmp = code(x) tmp = 2.71828182845904523536 ^ -x; end
code[x_] := N[Power[E, (-x)], $MachinePrecision]
\begin{array}{l}
\\
{e}^{\left(-x\right)}
\end{array}
Initial program 5.8%
/-rgt-identity5.8%
associate-/r/5.8%
exp-neg5.8%
remove-double-neg5.8%
Simplified5.8%
add-exp-log5.8%
*-un-lft-identity5.8%
exp-prod5.8%
log-div5.8%
add-log-exp5.8%
Applied egg-rr5.8%
Taylor expanded in x around inf 65.4%
neg-mul-165.4%
Simplified65.4%
Final simplification65.4%
herbie shell --seed 2024095
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))