
(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 7 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))) 2.0) (/ (fmod (exp x) (* 3.0 (log (cbrt E)))) (exp x)) (fmod 1.0 1.0)))
double code(double x) {
double tmp;
if ((fmod(exp(x), sqrt(cos(x))) * exp(-x)) <= 2.0) {
tmp = fmod(exp(x), (3.0 * log(cbrt(((double) M_E))))) / exp(x);
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) <= 2.0) tmp = Float64(rem(exp(x), Float64(3.0 * log(cbrt(exp(1))))) / exp(x)); else tmp = rem(1.0, 1.0); 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], 2.0], 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], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $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 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(3 \cdot \log \left(\sqrt[3]{e}\right)\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\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-cbrt60.3%
log-prod60.3%
Applied egg-rr60.1%
log-pow60.1%
distribute-lft1-in60.1%
metadata-eval60.1%
cos-060.1%
metadata-eval60.1%
exp-1-e60.1%
Simplified60.1%
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-log-exp0.0%
*-un-lft-identity0.0%
log-prod0.0%
metadata-eval0.0%
add-log-exp0.0%
Applied egg-rr95.8%
+-lft-identity95.8%
cos-095.8%
metadata-eval95.8%
Simplified95.8%
Taylor expanded in x around 0 96.0%
Final simplification66.8%
(FPCore (x) :precision binary64 (if (<= (* (fmod (exp x) (sqrt (cos x))) (exp (- x))) 2.0) (fmod (exp x) (* 3.0 (log (cbrt E)))) (fmod 1.0 1.0)))
double code(double x) {
double tmp;
if ((fmod(exp(x), sqrt(cos(x))) * exp(-x)) <= 2.0) {
tmp = fmod(exp(x), (3.0 * log(cbrt(((double) M_E)))));
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) <= 2.0) tmp = rem(exp(x), Float64(3.0 * log(cbrt(exp(1))))); else tmp = rem(1.0, 1.0); 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], 2.0], 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[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $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 2:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod \left(3 \cdot \log \left(\sqrt[3]{e}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\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%
Taylor expanded in x around 0 6.2%
add-log-exp7.3%
add-cube-cbrt60.3%
log-prod60.3%
Applied egg-rr59.2%
log-pow60.1%
distribute-lft1-in60.1%
metadata-eval60.1%
cos-060.1%
metadata-eval60.1%
exp-1-e60.1%
Simplified59.2%
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-log-exp0.0%
*-un-lft-identity0.0%
log-prod0.0%
metadata-eval0.0%
add-log-exp0.0%
Applied egg-rr95.8%
+-lft-identity95.8%
cos-095.8%
metadata-eval95.8%
Simplified95.8%
Taylor expanded in x around 0 96.0%
Final simplification66.1%
(FPCore (x) :precision binary64 (if (<= x 0.0005) (exp (- (log (fmod (exp x) 1.0)) x)) (fmod 1.0 1.0)))
double code(double x) {
double tmp;
if (x <= 0.0005) {
tmp = exp((log(fmod(exp(x), 1.0)) - x));
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0005d0) then
tmp = exp((log(mod(exp(x), 1.0d0)) - x))
else
tmp = mod(1.0d0, 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= 0.0005: tmp = math.exp((math.log(math.fmod(math.exp(x), 1.0)) - x)) else: tmp = math.fmod(1.0, 1.0) return tmp
function code(x) tmp = 0.0 if (x <= 0.0005) tmp = exp(Float64(log(rem(exp(x), 1.0)) - x)); else tmp = rem(1.0, 1.0); end return tmp end
code[x_] := If[LessEqual[x, 0.0005], N[Exp[N[(N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0005:\\
\;\;\;\;e^{\log \left(\left(e^{x}\right) \bmod 1\right) - x}\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if x < 5.0000000000000001e-4Initial program 7.3%
/-rgt-identity7.3%
associate-/r/7.2%
exp-neg7.3%
remove-double-neg7.3%
Simplified7.3%
add-log-exp7.2%
add-cube-cbrt59.7%
log-prod59.7%
Applied egg-rr59.5%
log-pow59.5%
distribute-lft1-in59.5%
metadata-eval59.5%
cos-059.5%
metadata-eval59.5%
exp-1-e59.5%
Simplified59.5%
add-log-exp59.5%
*-commutative59.5%
exp-to-pow59.5%
pow359.5%
add-cube-cbrt7.0%
log-E7.0%
add-exp-log7.0%
div-exp7.1%
Applied egg-rr7.1%
if 5.0000000000000001e-4 < x Initial program 0.0%
/-rgt-identity0.0%
associate-/r/0.0%
exp-neg0.0%
remove-double-neg0.0%
Simplified0.0%
add-log-exp0.0%
*-un-lft-identity0.0%
log-prod0.0%
metadata-eval0.0%
add-log-exp0.0%
Applied egg-rr100.0%
+-lft-identity100.0%
cos-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification23.8%
(FPCore (x) :precision binary64 (if (<= x 0.0005) (/ (fmod (exp x) 1.0) (exp x)) (fmod 1.0 1.0)))
double code(double x) {
double tmp;
if (x <= 0.0005) {
tmp = fmod(exp(x), 1.0) / exp(x);
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0005d0) then
tmp = mod(exp(x), 1.0d0) / exp(x)
else
tmp = mod(1.0d0, 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= 0.0005: tmp = math.fmod(math.exp(x), 1.0) / math.exp(x) else: tmp = math.fmod(1.0, 1.0) return tmp
function code(x) tmp = 0.0 if (x <= 0.0005) tmp = Float64(rem(exp(x), 1.0) / exp(x)); else tmp = rem(1.0, 1.0); end return tmp end
code[x_] := If[LessEqual[x, 0.0005], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0005:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if x < 5.0000000000000001e-4Initial program 7.3%
/-rgt-identity7.3%
associate-/r/7.2%
exp-neg7.3%
remove-double-neg7.3%
Simplified7.3%
Taylor expanded in x around 0 7.0%
if 5.0000000000000001e-4 < x Initial program 0.0%
/-rgt-identity0.0%
associate-/r/0.0%
exp-neg0.0%
remove-double-neg0.0%
Simplified0.0%
add-log-exp0.0%
*-un-lft-identity0.0%
log-prod0.0%
metadata-eval0.0%
add-log-exp0.0%
Applied egg-rr100.0%
+-lft-identity100.0%
cos-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification23.7%
(FPCore (x) :precision binary64 (if (<= x 0.0005) (* (fmod (exp x) 1.0) (- 1.0 x)) (fmod 1.0 1.0)))
double code(double x) {
double tmp;
if (x <= 0.0005) {
tmp = fmod(exp(x), 1.0) * (1.0 - x);
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0005d0) then
tmp = mod(exp(x), 1.0d0) * (1.0d0 - x)
else
tmp = mod(1.0d0, 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= 0.0005: tmp = math.fmod(math.exp(x), 1.0) * (1.0 - x) else: tmp = math.fmod(1.0, 1.0) return tmp
function code(x) tmp = 0.0 if (x <= 0.0005) tmp = Float64(rem(exp(x), 1.0) * Float64(1.0 - x)); else tmp = rem(1.0, 1.0); end return tmp end
code[x_] := If[LessEqual[x, 0.0005], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0005:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if x < 5.0000000000000001e-4Initial program 7.3%
/-rgt-identity7.3%
associate-/r/7.2%
exp-neg7.3%
remove-double-neg7.3%
Simplified7.3%
add-log-exp7.2%
add-cube-cbrt59.7%
log-prod59.7%
Applied egg-rr59.5%
log-pow59.5%
distribute-lft1-in59.5%
metadata-eval59.5%
cos-059.5%
metadata-eval59.5%
exp-1-e59.5%
Simplified59.5%
Taylor expanded in x around 0 6.9%
associate-*r*6.9%
neg-mul-16.9%
distribute-lft1-in6.9%
log-pow6.9%
log-E6.9%
metadata-eval6.9%
metadata-eval6.9%
distribute-rgt1-in6.9%
*-lft-identity6.9%
distribute-rgt-out6.9%
unsub-neg6.9%
Simplified6.9%
if 5.0000000000000001e-4 < x Initial program 0.0%
/-rgt-identity0.0%
associate-/r/0.0%
exp-neg0.0%
remove-double-neg0.0%
Simplified0.0%
add-log-exp0.0%
*-un-lft-identity0.0%
log-prod0.0%
metadata-eval0.0%
add-log-exp0.0%
Applied egg-rr100.0%
+-lft-identity100.0%
cos-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification23.6%
(FPCore (x) :precision binary64 (if (<= x 0.0005) (fmod (exp x) 1.0) (fmod 1.0 1.0)))
double code(double x) {
double tmp;
if (x <= 0.0005) {
tmp = fmod(exp(x), 1.0);
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0005d0) then
tmp = mod(exp(x), 1.0d0)
else
tmp = mod(1.0d0, 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= 0.0005: tmp = math.fmod(math.exp(x), 1.0) else: tmp = math.fmod(1.0, 1.0) return tmp
function code(x) tmp = 0.0 if (x <= 0.0005) tmp = rem(exp(x), 1.0); else tmp = rem(1.0, 1.0); end return tmp end
code[x_] := If[LessEqual[x, 0.0005], N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0005:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if x < 5.0000000000000001e-4Initial program 7.3%
Taylor expanded in x around 0 6.1%
Taylor expanded in x around 0 6.2%
if 5.0000000000000001e-4 < x Initial program 0.0%
/-rgt-identity0.0%
associate-/r/0.0%
exp-neg0.0%
remove-double-neg0.0%
Simplified0.0%
add-log-exp0.0%
*-un-lft-identity0.0%
log-prod0.0%
metadata-eval0.0%
add-log-exp0.0%
Applied egg-rr100.0%
+-lft-identity100.0%
cos-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification23.0%
(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.9%
/-rgt-identity5.9%
associate-/r/5.9%
exp-neg5.9%
remove-double-neg5.9%
Simplified5.9%
add-log-exp5.9%
*-un-lft-identity5.9%
log-prod5.9%
metadata-eval5.9%
add-log-exp5.9%
Applied egg-rr21.2%
+-lft-identity21.2%
cos-021.2%
metadata-eval21.2%
Simplified21.2%
Taylor expanded in x around 0 21.2%
Final simplification21.2%
herbie shell --seed 2024019
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))