
(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 6 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 (<= x -5e-310)
(/
(fmod
(exp x)
(sqrt (+ (log (pow (cbrt (exp (cos x))) 2.0)) (log (cbrt E)))))
(exp x))
(/ (fmod x 1.0) (exp x))))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = fmod(exp(x), sqrt((log(pow(cbrt(exp(cos(x))), 2.0)) + log(cbrt(((double) M_E)))))) / exp(x);
} else {
tmp = fmod(x, 1.0) / exp(x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = Float64(rem(exp(x), sqrt(Float64(log((cbrt(exp(cos(x))) ^ 2.0)) + log(cbrt(exp(1)))))) / exp(x)); else tmp = Float64(rem(x, 1.0) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -5e-310], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[(N[Log[N[Power[N[Power[N[Exp[N[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[N[Power[E, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\log \left({\left(\sqrt[3]{e^{\cos x}}\right)}^{2}\right) + \log \left(\sqrt[3]{e}\right)}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 5.1%
/-rgt-identity5.1%
associate-/r/5.1%
exp-neg5.1%
remove-double-neg5.1%
Simplified5.1%
add-log-exp5.1%
add-cube-cbrt97.9%
log-prod97.9%
pow297.9%
Applied egg-rr97.9%
Taylor expanded in x around 0 97.9%
exp-1-e97.9%
Simplified97.9%
if -4.999999999999985e-310 < x Initial program 5.2%
/-rgt-identity5.2%
associate-/r/5.2%
exp-neg5.2%
remove-double-neg5.2%
Simplified5.2%
Taylor expanded in x around 0 36.4%
+-commutative36.4%
Simplified36.4%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around 0 98.5%
Taylor expanded in x around 0 98.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (exp (cos x)))))
(if (<= x -5e-310)
(fmod 1.0 (sqrt (+ (log (pow t_0 2.0)) (log t_0))))
(/ (fmod x 1.0) (exp x)))))
double code(double x) {
double t_0 = cbrt(exp(cos(x)));
double tmp;
if (x <= -5e-310) {
tmp = fmod(1.0, sqrt((log(pow(t_0, 2.0)) + log(t_0))));
} else {
tmp = fmod(x, 1.0) / exp(x);
}
return tmp;
}
function code(x) t_0 = cbrt(exp(cos(x))) tmp = 0.0 if (x <= -5e-310) tmp = rem(1.0, sqrt(Float64(log((t_0 ^ 2.0)) + log(t_0)))); else tmp = Float64(rem(x, 1.0) / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[Exp[N[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[x, -5e-310], N[With[{TMP1 = 1.0, 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[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{e^{\cos x}}\\
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(1 \bmod \left(\sqrt{\log \left({t\_0}^{2}\right) + \log t\_0}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 5.1%
/-rgt-identity5.1%
associate-/r/5.1%
exp-neg5.1%
remove-double-neg5.1%
Simplified5.1%
Taylor expanded in x around 0 4.1%
Taylor expanded in x around 0 3.5%
add-log-exp5.1%
add-cube-cbrt97.9%
log-prod97.9%
pow297.9%
Applied egg-rr97.3%
if -4.999999999999985e-310 < x Initial program 5.2%
/-rgt-identity5.2%
associate-/r/5.2%
exp-neg5.2%
remove-double-neg5.2%
Simplified5.2%
Taylor expanded in x around 0 36.4%
+-commutative36.4%
Simplified36.4%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around 0 98.5%
Taylor expanded in x around 0 98.6%
(FPCore (x) :precision binary64 (if (<= x -5e-310) (/ (fmod (* (/ (exp x) (sqrt E)) (/ E (sqrt E))) (sqrt (cos x))) (exp x)) (/ (fmod x 1.0) (exp x))))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = fmod(((exp(x) / sqrt(((double) M_E))) * (((double) M_E) / sqrt(((double) M_E)))), sqrt(cos(x))) / exp(x);
} else {
tmp = fmod(x, 1.0) / exp(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -5e-310: tmp = math.fmod(((math.exp(x) / math.sqrt(math.e)) * (math.e / math.sqrt(math.e))), math.sqrt(math.cos(x))) / math.exp(x) else: tmp = math.fmod(x, 1.0) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = Float64(rem(Float64(Float64(exp(x) / sqrt(exp(1))) * Float64(exp(1) / sqrt(exp(1)))), sqrt(cos(x))) / exp(x)); else tmp = Float64(rem(x, 1.0) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -5e-310], N[(N[With[{TMP1 = N[(N[(N[Exp[x], $MachinePrecision] / N[Sqrt[E], $MachinePrecision]), $MachinePrecision] * N[(E / N[Sqrt[E], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{\left(\left(\frac{e^{x}}{\sqrt{e}} \cdot \frac{e}{\sqrt{e}}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 5.1%
/-rgt-identity5.1%
associate-/r/5.1%
exp-neg5.1%
remove-double-neg5.1%
Simplified5.1%
add-cube-cbrt5.1%
pow35.1%
Applied egg-rr5.1%
rem-cube-cbrt5.1%
*-un-lft-identity5.1%
pow-exp5.1%
e-exp-15.1%
expm1-log1p-u5.1%
log1p-define5.1%
+-commutative5.1%
expm1-undefine5.1%
add-exp-log5.1%
pow-div5.1%
pow15.1%
e-exp-15.1%
pow-exp5.1%
*-un-lft-identity5.1%
exp-sum5.1%
e-exp-15.1%
add-sqr-sqrt96.3%
times-frac96.3%
Applied egg-rr96.3%
if -4.999999999999985e-310 < x Initial program 5.2%
/-rgt-identity5.2%
associate-/r/5.2%
exp-neg5.2%
remove-double-neg5.2%
Simplified5.2%
Taylor expanded in x around 0 36.4%
+-commutative36.4%
Simplified36.4%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around 0 98.5%
Taylor expanded in x around 0 98.6%
(FPCore (x) :precision binary64 (if (<= x -5e-309) (/ (fmod (* x (+ 1.0 (/ 1.0 x))) (sqrt (cos x))) (exp x)) (/ (fmod x 1.0) (exp x))))
double code(double x) {
double tmp;
if (x <= -5e-309) {
tmp = fmod((x * (1.0 + (1.0 / x))), sqrt(cos(x))) / exp(x);
} else {
tmp = fmod(x, 1.0) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-309)) then
tmp = mod((x * (1.0d0 + (1.0d0 / x))), sqrt(cos(x))) / exp(x)
else
tmp = mod(x, 1.0d0) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -5e-309: tmp = math.fmod((x * (1.0 + (1.0 / x))), math.sqrt(math.cos(x))) / math.exp(x) else: tmp = math.fmod(x, 1.0) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -5e-309) tmp = Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), sqrt(cos(x))) / exp(x)); else tmp = Float64(rem(x, 1.0) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -5e-309], N[(N[With[{TMP1 = N[(x * N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-309}:\\
\;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -4.9999999999999995e-309Initial program 5.1%
/-rgt-identity5.1%
associate-/r/5.1%
exp-neg5.1%
remove-double-neg5.1%
Simplified5.1%
Taylor expanded in x around 0 4.7%
+-commutative4.7%
Simplified4.7%
Taylor expanded in x around inf 22.9%
if -4.9999999999999995e-309 < x Initial program 5.2%
/-rgt-identity5.2%
associate-/r/5.2%
exp-neg5.2%
remove-double-neg5.2%
Simplified5.2%
Taylor expanded in x around 0 36.4%
+-commutative36.4%
Simplified36.4%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around 0 98.5%
Taylor expanded in x around 0 98.6%
(FPCore (x) :precision binary64 (/ (fmod x 1.0) (exp x)))
double code(double x) {
return fmod(x, 1.0) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(x, 1.0d0) / exp(x)
end function
def code(x): return math.fmod(x, 1.0) / math.exp(x)
function code(x) return Float64(rem(x, 1.0) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \bmod 1\right)}{e^{x}}
\end{array}
Initial program 5.2%
/-rgt-identity5.2%
associate-/r/5.2%
exp-neg5.2%
remove-double-neg5.2%
Simplified5.2%
Taylor expanded in x around 0 24.7%
+-commutative24.7%
Simplified24.7%
Taylor expanded in x around inf 63.2%
Taylor expanded in x around 0 63.2%
Taylor expanded in x around 0 63.2%
(FPCore (x) :precision binary64 (fmod 1.0 1.0))
double code(double x) {
return fmod(1.0, 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(1.0d0, 1.0d0)
end function
def code(x): return math.fmod(1.0, 1.0)
function code(x) return rem(1.0, 1.0) end
code[x_] := N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(1 \bmod 1\right)
\end{array}
Initial program 5.2%
/-rgt-identity5.2%
associate-/r/5.2%
exp-neg5.2%
remove-double-neg5.2%
Simplified5.2%
Taylor expanded in x around 0 4.5%
Taylor expanded in x around 0 4.3%
Taylor expanded in x around 0 4.9%
Taylor expanded in x around 0 23.4%
herbie shell --seed 2024179
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))