
(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 5 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 (if (<= (* (fmod (exp x) (sqrt (cos x))) (exp (- x))) 0.0) (exp x) (/ (fmod (exp x) (cbrt (pow (cos x) 1.5))) (exp x))))
double code(double x) {
double tmp;
if ((fmod(exp(x), sqrt(cos(x))) * exp(-x)) <= 0.0) {
tmp = exp(x);
} else {
tmp = fmod(exp(x), cbrt(pow(cos(x), 1.5))) / exp(x);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) <= 0.0) tmp = exp(x); else tmp = Float64(rem(exp(x), cbrt((cos(x) ^ 1.5))) / exp(x)); 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], 0.0], N[Exp[x], $MachinePrecision], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $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 0:\\
\;\;\;\;e^{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt[3]{{\cos x}^{1.5}}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0Initial program 4.4%
exp-neg4.4%
div-inv4.4%
add-cube-cbrt4.4%
pow34.4%
pow-to-exp4.4%
Applied egg-rr4.4%
Taylor expanded in x around inf 49.4%
*-commutative49.4%
Simplified49.4%
Taylor expanded in x around 0 49.4%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 14.3%
/-rgt-identity14.3%
associate-/r/14.3%
exp-neg14.3%
remove-double-neg14.3%
Simplified14.3%
add-cbrt-cube14.3%
pow314.4%
pow1/214.4%
pow-pow14.4%
metadata-eval14.4%
Applied egg-rr14.4%
Final simplification40.7%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (exp (sqrt (cos x)))))) (/ (fmod (exp x) (+ (log (pow t_0 2.0)) (log t_0))) (exp x))))
double code(double x) {
double t_0 = cbrt(exp(sqrt(cos(x))));
return fmod(exp(x), (log(pow(t_0, 2.0)) + log(t_0))) / exp(x);
}
function code(x) t_0 = cbrt(exp(sqrt(cos(x)))) return Float64(rem(exp(x), Float64(log((t_0 ^ 2.0)) + log(t_0))) / exp(x)) end
code[x_] := Block[{t$95$0 = N[Power[N[Exp[N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Log[N[Power[t$95$0, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$0], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{e^{\sqrt{\cos x}}}\\
\frac{\left(\left(e^{x}\right) \bmod \left(\log \left({t\_0}^{2}\right) + \log t\_0\right)\right)}{e^{x}}
\end{array}
\end{array}
Initial program 6.8%
/-rgt-identity6.8%
associate-/r/6.8%
exp-neg6.8%
remove-double-neg6.8%
Simplified6.8%
add-log-exp6.8%
add-cube-cbrt40.6%
log-prod40.6%
pow240.6%
Applied egg-rr40.6%
Final simplification40.6%
(FPCore (x) :precision binary64 (let* ((t_0 (fmod (exp x) (sqrt (cos x))))) (if (<= (* t_0 (exp (- x))) 0.0) (exp x) (/ t_0 (exp x)))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double tmp;
if ((t_0 * exp(-x)) <= 0.0) {
tmp = exp(x);
} else {
tmp = t_0 / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = mod(exp(x), sqrt(cos(x)))
if ((t_0 * exp(-x)) <= 0.0d0) then
tmp = exp(x)
else
tmp = t_0 / exp(x)
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) tmp = 0 if (t_0 * math.exp(-x)) <= 0.0: tmp = math.exp(x) else: tmp = t_0 / math.exp(x) return tmp
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) tmp = 0.0 if (Float64(t_0 * exp(Float64(-x))) <= 0.0) tmp = exp(x); else tmp = Float64(t_0 / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]}, If[LessEqual[N[(t$95$0 * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 0.0], N[Exp[x], $MachinePrecision], N[(t$95$0 / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;t\_0 \cdot e^{-x} \leq 0:\\
\;\;\;\;e^{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{e^{x}}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0Initial program 4.4%
exp-neg4.4%
div-inv4.4%
add-cube-cbrt4.4%
pow34.4%
pow-to-exp4.4%
Applied egg-rr4.4%
Taylor expanded in x around inf 49.4%
*-commutative49.4%
Simplified49.4%
Taylor expanded in x around 0 49.4%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 14.3%
/-rgt-identity14.3%
associate-/r/14.3%
exp-neg14.3%
remove-double-neg14.3%
Simplified14.3%
Final simplification40.7%
(FPCore (x) :precision binary64 (exp (fabs x)))
double code(double x) {
return exp(fabs(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(abs(x))
end function
public static double code(double x) {
return Math.exp(Math.abs(x));
}
def code(x): return math.exp(math.fabs(x))
function code(x) return exp(abs(x)) end
function tmp = code(x) tmp = exp(abs(x)); end
code[x_] := N[Exp[N[Abs[x], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left|x\right|}
\end{array}
Initial program 6.8%
exp-neg6.8%
div-inv6.8%
add-cube-cbrt6.8%
pow36.8%
pow-to-exp6.8%
Applied egg-rr5.1%
Taylor expanded in x around inf 38.9%
*-commutative38.9%
Simplified38.9%
associate-*l*38.9%
metadata-eval38.9%
*-rgt-identity38.9%
add-sqr-sqrt2.6%
sqrt-prod38.9%
rem-sqrt-square38.9%
Applied egg-rr38.9%
Final simplification38.9%
(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(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.8%
exp-neg6.8%
div-inv6.8%
add-cube-cbrt6.8%
pow36.8%
pow-to-exp6.8%
Applied egg-rr5.1%
Taylor expanded in x around inf 38.9%
*-commutative38.9%
Simplified38.9%
Taylor expanded in x around 0 38.9%
Final simplification38.9%
herbie shell --seed 2024067
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))