
(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 (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.5%
/-rgt-identity4.5%
associate-/r/4.5%
exp-neg4.5%
remove-double-neg4.5%
Simplified4.5%
add-log-exp4.5%
add-cube-cbrt53.3%
log-prod53.3%
pow253.3%
Applied egg-rr53.3%
log-pow53.3%
distribute-lft1-in53.3%
metadata-eval53.3%
Simplified53.3%
Taylor expanded in x around 0 4.5%
unpow1/353.3%
exp-1-e53.3%
Simplified53.3%
add-exp-log53.3%
div-inv53.3%
exp-neg53.3%
log-prod53.3%
add-log-exp53.3%
*-commutative53.3%
exp-to-pow53.3%
pow353.3%
add-cube-cbrt4.5%
log-E4.5%
add-log-exp4.5%
add-sqr-sqrt1.6%
sqrt-unprod4.5%
sqr-neg4.5%
sqrt-unprod2.9%
add-sqr-sqrt4.5%
Applied egg-rr4.5%
Taylor expanded in x around inf 53.3%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 15.3%
/-rgt-identity15.3%
associate-/r/15.2%
exp-neg15.3%
remove-double-neg15.3%
Simplified15.3%
Final simplification42.9%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (* 3.0 (log (cbrt (exp (sqrt (cos x))))))) (exp x)))
double code(double x) {
return fmod(exp(x), (3.0 * log(cbrt(exp(sqrt(cos(x))))))) / exp(x);
}
function code(x) return Float64(rem(exp(x), Float64(3.0 * log(cbrt(exp(sqrt(cos(x))))))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(3.0 * N[Log[N[Power[N[Exp[N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(e^{x}\right) \bmod \left(3 \cdot \log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right)\right)\right)}{e^{x}}
\end{array}
Initial program 7.4%
/-rgt-identity7.4%
associate-/r/7.4%
exp-neg7.4%
remove-double-neg7.4%
Simplified7.4%
add-log-exp7.4%
add-cube-cbrt42.8%
log-prod42.8%
pow242.8%
Applied egg-rr42.8%
log-pow42.8%
distribute-lft1-in42.8%
metadata-eval42.8%
Simplified42.8%
Final simplification42.8%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (* 3.0 (log (cbrt E)))) (exp x)))
double code(double x) {
return fmod(exp(x), (3.0 * log(cbrt(((double) M_E))))) / exp(x);
}
function code(x) return Float64(rem(exp(x), Float64(3.0 * log(cbrt(exp(1))))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(3.0 * N[Log[N[Power[E, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(e^{x}\right) \bmod \left(3 \cdot \log \left(\sqrt[3]{e}\right)\right)\right)}{e^{x}}
\end{array}
Initial program 7.4%
/-rgt-identity7.4%
associate-/r/7.4%
exp-neg7.4%
remove-double-neg7.4%
Simplified7.4%
add-log-exp7.4%
add-cube-cbrt42.8%
log-prod42.8%
pow242.8%
Applied egg-rr42.8%
log-pow42.8%
distribute-lft1-in42.8%
metadata-eval42.8%
Simplified42.8%
Taylor expanded in x around 0 7.4%
unpow1/342.8%
exp-1-e42.8%
Simplified42.8%
Final simplification42.8%
(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 7.4%
/-rgt-identity7.4%
associate-/r/7.4%
exp-neg7.4%
remove-double-neg7.4%
Simplified7.4%
add-log-exp7.4%
add-cube-cbrt42.8%
log-prod42.8%
pow242.8%
Applied egg-rr42.8%
log-pow42.8%
distribute-lft1-in42.8%
metadata-eval42.8%
Simplified42.8%
Taylor expanded in x around 0 7.4%
unpow1/342.8%
exp-1-e42.8%
Simplified42.8%
add-exp-log42.8%
div-inv42.8%
exp-neg42.8%
log-prod42.8%
add-log-exp42.8%
*-commutative42.8%
exp-to-pow42.8%
pow342.8%
add-cube-cbrt7.3%
log-E7.3%
add-log-exp7.4%
add-sqr-sqrt4.7%
sqrt-unprod7.4%
sqr-neg7.4%
sqrt-unprod2.7%
add-sqr-sqrt5.8%
Applied egg-rr5.8%
Taylor expanded in x around inf 41.2%
Final simplification41.2%
herbie shell --seed 2024027
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))