
(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) 1.0 (/ (fmod x (sqrt (cos x))) (exp x))))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = 1.0;
} else {
tmp = fmod(x, sqrt(cos(x))) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-310)) then
tmp = 1.0d0
else
tmp = mod(x, sqrt(cos(x))) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -5e-310: tmp = 1.0 else: tmp = math.fmod(x, math.sqrt(math.cos(x))) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = 1.0; else tmp = Float64(rem(x, sqrt(cos(x))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -5e-310], 1.0, N[(N[With[{TMP1 = x, TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, 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}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 10.0%
/-rgt-identity10.0%
associate-/r/10.0%
exp-neg10.0%
remove-double-neg10.0%
Simplified10.0%
add-exp-log10.0%
div-exp10.1%
Applied egg-rr10.1%
Taylor expanded in x around inf 94.2%
neg-mul-194.2%
Simplified94.2%
Taylor expanded in x around 0 100.0%
if -4.999999999999985e-310 < x Initial program 6.1%
/-rgt-identity6.1%
associate-/r/6.1%
exp-neg6.1%
remove-double-neg6.1%
Simplified6.1%
Taylor expanded in x around 0 37.7%
+-commutative37.7%
Simplified37.7%
Taylor expanded in x around inf 97.6%
(FPCore (x) :precision binary64 (if (<= x 0.6) 1.0 (/ (fmod 1.0 (sqrt (cos x))) (exp x))))
double code(double x) {
double tmp;
if (x <= 0.6) {
tmp = 1.0;
} else {
tmp = fmod(1.0, sqrt(cos(x))) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.6d0) then
tmp = 1.0d0
else
tmp = mod(1.0d0, sqrt(cos(x))) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= 0.6: tmp = 1.0 else: tmp = math.fmod(1.0, math.sqrt(math.cos(x))) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= 0.6) tmp = 1.0; else tmp = Float64(rem(1.0, sqrt(cos(x))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, 0.6], 1.0, N[(N[With[{TMP1 = 1.0, TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.6:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < 0.599999999999999978Initial program 9.5%
/-rgt-identity9.5%
associate-/r/9.5%
exp-neg9.5%
remove-double-neg9.5%
Simplified9.5%
add-exp-log9.5%
div-exp9.6%
Applied egg-rr9.6%
Taylor expanded in x around inf 53.0%
neg-mul-153.0%
Simplified53.0%
Taylor expanded in x around 0 56.0%
if 0.599999999999999978 < x Initial program 0.4%
/-rgt-identity0.4%
associate-/r/0.4%
exp-neg0.4%
remove-double-neg0.4%
Simplified0.4%
Taylor expanded in x around 0 98.4%
(FPCore (x) :precision binary64 (if (<= x -4e-16) 1.0 (exp (- x))))
double code(double x) {
double tmp;
if (x <= -4e-16) {
tmp = 1.0;
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4d-16)) then
tmp = 1.0d0
else
tmp = exp(-x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -4e-16) {
tmp = 1.0;
} else {
tmp = Math.exp(-x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -4e-16: tmp = 1.0 else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if (x <= -4e-16) tmp = 1.0; else tmp = exp(Float64(-x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4e-16) tmp = 1.0; else tmp = exp(-x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4e-16], 1.0, N[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-16}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -3.9999999999999999e-16Initial program 72.2%
/-rgt-identity72.2%
associate-/r/72.0%
exp-neg72.7%
remove-double-neg72.7%
Simplified72.7%
add-exp-log72.7%
div-exp73.6%
Applied egg-rr73.6%
Taylor expanded in x around inf 41.6%
neg-mul-141.6%
Simplified41.6%
Taylor expanded in x around 0 100.0%
if -3.9999999999999999e-16 < x Initial program 4.9%
/-rgt-identity4.9%
associate-/r/4.9%
exp-neg4.9%
remove-double-neg4.9%
Simplified4.9%
add-exp-log4.9%
div-exp4.9%
Applied egg-rr4.9%
Taylor expanded in x around inf 62.4%
neg-mul-162.4%
Simplified62.4%
(FPCore (x) :precision binary64 (if (<= x 5e-182) 1.0 (/ 1.0 (+ 1.0 (* x (+ 1.0 (* x (+ 0.5 (* x 0.16666666666666666)))))))))
double code(double x) {
double tmp;
if (x <= 5e-182) {
tmp = 1.0;
} else {
tmp = 1.0 / (1.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5d-182) then
tmp = 1.0d0
else
tmp = 1.0d0 / (1.0d0 + (x * (1.0d0 + (x * (0.5d0 + (x * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5e-182) {
tmp = 1.0;
} else {
tmp = 1.0 / (1.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666))))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 5e-182: tmp = 1.0 else: tmp = 1.0 / (1.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666)))))) return tmp
function code(x) tmp = 0.0 if (x <= 5e-182) tmp = 1.0; else tmp = Float64(1.0 / Float64(1.0 + Float64(x * Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5e-182) tmp = 1.0; else tmp = 1.0 / (1.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5e-182], 1.0, N[(1.0 / N[(1.0 + N[(x * N[(1.0 + N[(x * N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{-182}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + x \cdot \left(1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if x < 5.00000000000000024e-182Initial program 9.5%
/-rgt-identity9.5%
associate-/r/9.5%
exp-neg9.5%
remove-double-neg9.5%
Simplified9.5%
add-exp-log9.5%
div-exp9.6%
Applied egg-rr9.6%
Taylor expanded in x around inf 76.5%
neg-mul-176.5%
Simplified76.5%
Taylor expanded in x around 0 81.1%
if 5.00000000000000024e-182 < x Initial program 5.8%
/-rgt-identity5.8%
associate-/r/5.8%
exp-neg5.8%
remove-double-neg5.8%
Simplified5.8%
add-exp-log5.8%
div-exp5.8%
Applied egg-rr5.8%
Taylor expanded in x around inf 43.9%
neg-mul-143.9%
Simplified43.9%
exp-neg43.9%
Applied egg-rr43.9%
Taylor expanded in x around 0 31.7%
*-commutative31.7%
Simplified31.7%
(FPCore (x) :precision binary64 (if (<= x 5e-277) 1.0 (/ 1.0 (+ 1.0 (* x (+ 1.0 (* x 0.5)))))))
double code(double x) {
double tmp;
if (x <= 5e-277) {
tmp = 1.0;
} else {
tmp = 1.0 / (1.0 + (x * (1.0 + (x * 0.5))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5d-277) then
tmp = 1.0d0
else
tmp = 1.0d0 / (1.0d0 + (x * (1.0d0 + (x * 0.5d0))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5e-277) {
tmp = 1.0;
} else {
tmp = 1.0 / (1.0 + (x * (1.0 + (x * 0.5))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 5e-277: tmp = 1.0 else: tmp = 1.0 / (1.0 + (x * (1.0 + (x * 0.5)))) return tmp
function code(x) tmp = 0.0 if (x <= 5e-277) tmp = 1.0; else tmp = Float64(1.0 / Float64(1.0 + Float64(x * Float64(1.0 + Float64(x * 0.5))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5e-277) tmp = 1.0; else tmp = 1.0 / (1.0 + (x * (1.0 + (x * 0.5)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5e-277], 1.0, N[(1.0 / N[(1.0 + N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{-277}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + x \cdot \left(1 + x \cdot 0.5\right)}\\
\end{array}
\end{array}
if x < 5e-277Initial program 10.0%
/-rgt-identity10.0%
associate-/r/10.0%
exp-neg10.0%
remove-double-neg10.0%
Simplified10.0%
add-exp-log10.0%
div-exp10.1%
Applied egg-rr10.1%
Taylor expanded in x around inf 88.8%
neg-mul-188.8%
Simplified88.8%
Taylor expanded in x around 0 94.3%
if 5e-277 < x Initial program 5.9%
/-rgt-identity5.9%
associate-/r/5.9%
exp-neg5.9%
remove-double-neg5.9%
Simplified5.9%
add-exp-log5.9%
div-exp5.9%
Applied egg-rr5.9%
Taylor expanded in x around inf 38.1%
neg-mul-138.1%
Simplified38.1%
exp-neg38.1%
Applied egg-rr38.1%
Taylor expanded in x around 0 23.6%
*-commutative23.6%
Simplified23.6%
(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 7.8%
/-rgt-identity7.8%
associate-/r/7.8%
exp-neg7.8%
remove-double-neg7.8%
Simplified7.8%
add-exp-log7.8%
div-exp7.9%
Applied egg-rr7.9%
Taylor expanded in x around inf 61.5%
neg-mul-161.5%
Simplified61.5%
Taylor expanded in x around 0 46.1%
herbie shell --seed 2024181
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))