
(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 (if (<= x -5e-16) (exp (- (log (fmod (exp x) 1.0)) x)) (exp (- x))))
double code(double x) {
double tmp;
if (x <= -5e-16) {
tmp = exp((log(fmod(exp(x), 1.0)) - x));
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-16)) then
tmp = exp((log(mod(exp(x), 1.0d0)) - x))
else
tmp = exp(-x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -5e-16: tmp = math.exp((math.log(math.fmod(math.exp(x), 1.0)) - x)) else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if (x <= -5e-16) tmp = exp(Float64(log(rem(exp(x), 1.0)) - x)); else tmp = exp(Float64(-x)); end return tmp end
code[x_] := If[LessEqual[x, -5e-16], 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[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-16}:\\
\;\;\;\;e^{\log \left(\left(e^{x}\right) \bmod 1\right) - x}\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -5.0000000000000004e-16Initial program 91.3%
exp-neg91.3%
associate-*r/91.7%
*-rgt-identity91.7%
Simplified91.7%
Taylor expanded in x around 0 91.7%
add-exp-log91.7%
div-exp91.9%
Applied egg-rr91.9%
if -5.0000000000000004e-16 < x Initial program 4.4%
exp-neg4.4%
associate-*r/4.4%
*-rgt-identity4.4%
Simplified4.4%
Taylor expanded in x around 0 4.1%
add-exp-log4.1%
div-exp4.1%
Applied egg-rr4.1%
Taylor expanded in x around inf 58.6%
neg-mul-158.6%
Simplified58.6%
Final simplification60.2%
(FPCore (x) :precision binary64 (if (<= x -5e-16) (/ (fmod (exp x) 1.0) (exp x)) (exp (- x))))
double code(double x) {
double tmp;
if (x <= -5e-16) {
tmp = fmod(exp(x), 1.0) / exp(x);
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-16)) then
tmp = mod(exp(x), 1.0d0) / exp(x)
else
tmp = exp(-x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -5e-16: tmp = math.fmod(math.exp(x), 1.0) / math.exp(x) else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if (x <= -5e-16) tmp = Float64(rem(exp(x), 1.0) / exp(x)); else tmp = exp(Float64(-x)); end return tmp end
code[x_] := If[LessEqual[x, -5e-16], 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[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-16}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -5.0000000000000004e-16Initial program 91.3%
exp-neg91.3%
associate-*r/91.7%
*-rgt-identity91.7%
Simplified91.7%
Taylor expanded in x around 0 91.7%
if -5.0000000000000004e-16 < x Initial program 4.4%
exp-neg4.4%
associate-*r/4.4%
*-rgt-identity4.4%
Simplified4.4%
Taylor expanded in x around 0 4.1%
add-exp-log4.1%
div-exp4.1%
Applied egg-rr4.1%
Taylor expanded in x around inf 58.6%
neg-mul-158.6%
Simplified58.6%
Final simplification60.2%
(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(Float64(-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 8.5%
exp-neg8.5%
associate-*r/8.5%
*-rgt-identity8.5%
Simplified8.5%
Taylor expanded in x around 0 8.3%
add-exp-log8.3%
div-exp8.3%
Applied egg-rr8.3%
Taylor expanded in x around inf 57.8%
neg-mul-157.8%
Simplified57.8%
Final simplification57.8%
herbie shell --seed 2023285
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))