
(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 2 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-309) 1.0 (exp (- x))))
double code(double x) {
double tmp;
if (x <= 5e-309) {
tmp = 1.0;
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5d-309) then
tmp = 1.0d0
else
tmp = exp(-x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5e-309) {
tmp = 1.0;
} else {
tmp = Math.exp(-x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 5e-309: tmp = 1.0 else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if (x <= 5e-309) tmp = 1.0; else tmp = exp(Float64(-x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5e-309) tmp = 1.0; else tmp = exp(-x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5e-309], 1.0, N[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{-309}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < 4.9999999999999995e-309Initial program 8.4%
exp-neg8.4%
associate-*r/8.5%
*-rgt-identity8.5%
Simplified8.5%
add-exp-log8.5%
div-exp8.5%
Applied egg-rr8.5%
add-cube-cbrt8.5%
pow38.5%
Applied egg-rr8.5%
Taylor expanded in x around inf 99.0%
if 4.9999999999999995e-309 < x Initial program 4.7%
exp-neg4.7%
associate-*r/4.7%
*-rgt-identity4.7%
Simplified4.7%
add-exp-log4.7%
div-exp4.7%
Applied egg-rr4.7%
Taylor expanded in x around inf 38.4%
neg-mul-138.4%
Simplified38.4%
Final simplification60.7%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 6.1%
exp-neg6.1%
associate-*r/6.1%
*-rgt-identity6.1%
Simplified6.1%
add-exp-log6.1%
div-exp6.1%
Applied egg-rr6.1%
add-cube-cbrt6.1%
pow36.1%
Applied egg-rr6.1%
Taylor expanded in x around inf 39.1%
Final simplification39.1%
herbie shell --seed 2023207
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))