
(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 8 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 -1e-309)
(/
(fmod
(exp x)
(sqrt (+ (log (pow (cbrt (exp (cos x))) 2.0)) (log (cbrt E)))))
(exp x))
(/ (fmod x (sqrt (cos x))) (exp x))))
double code(double x) {
double tmp;
if (x <= -1e-309) {
tmp = fmod(exp(x), sqrt((log(pow(cbrt(exp(cos(x))), 2.0)) + log(cbrt(((double) M_E)))))) / exp(x);
} else {
tmp = fmod(x, sqrt(cos(x))) / exp(x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1e-309) 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, sqrt(cos(x))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -1e-309], 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 = 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 -1 \cdot 10^{-309}:\\
\;\;\;\;\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 \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -1.000000000000002e-309Initial program 6.8%
/-rgt-identity6.8%
associate-/r/6.7%
exp-neg6.8%
remove-double-neg6.8%
Simplified6.8%
add-log-exp6.8%
add-cube-cbrt99.0%
log-prod99.0%
pow299.0%
Applied egg-rr99.0%
Taylor expanded in x around 0 99.0%
exp-1-e99.0%
Simplified99.0%
if -1.000000000000002e-309 < x Initial program 3.6%
/-rgt-identity3.6%
associate-/r/3.6%
exp-neg3.6%
remove-double-neg3.6%
Simplified3.6%
Taylor expanded in x around 0 40.1%
+-commutative40.1%
Simplified40.1%
Taylor expanded in x around inf 99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))))
(if (<= x -6e-309)
(/ (fmod (* x (+ 1.0 (/ 1.0 x))) t_0) (+ x 1.0))
(/ (fmod x t_0) (exp x)))))
double code(double x) {
double t_0 = sqrt(cos(x));
double tmp;
if (x <= -6e-309) {
tmp = fmod((x * (1.0 + (1.0 / x))), t_0) / (x + 1.0);
} else {
tmp = fmod(x, t_0) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(cos(x))
if (x <= (-6d-309)) then
tmp = mod((x * (1.0d0 + (1.0d0 / x))), t_0) / (x + 1.0d0)
else
tmp = mod(x, t_0) / exp(x)
end if
code = tmp
end function
def code(x): t_0 = math.sqrt(math.cos(x)) tmp = 0 if x <= -6e-309: tmp = math.fmod((x * (1.0 + (1.0 / x))), t_0) / (x + 1.0) else: tmp = math.fmod(x, t_0) / math.exp(x) return tmp
function code(x) t_0 = sqrt(cos(x)) tmp = 0.0 if (x <= -6e-309) tmp = Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), t_0) / Float64(x + 1.0)); else tmp = Float64(rem(x, t_0) / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -6e-309], N[(N[With[{TMP1 = N[(x * N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = x, TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
\mathbf{if}\;x \leq -6 \cdot 10^{-309}:\\
\;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod t\_0\right)}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod t\_0\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -6.000000000000001e-309Initial program 6.8%
/-rgt-identity6.8%
associate-/r/6.7%
exp-neg6.8%
remove-double-neg6.8%
Simplified6.8%
Taylor expanded in x around 0 5.4%
+-commutative5.4%
Simplified5.4%
Taylor expanded in x around 0 6.1%
+-commutative5.4%
Simplified6.1%
Taylor expanded in x around inf 19.7%
if -6.000000000000001e-309 < x Initial program 3.6%
/-rgt-identity3.6%
associate-/r/3.6%
exp-neg3.6%
remove-double-neg3.6%
Simplified3.6%
Taylor expanded in x around 0 40.1%
+-commutative40.1%
Simplified40.1%
Taylor expanded in x around inf 99.9%
(FPCore (x) :precision binary64 (if (<= x -6e-309) (/ (fmod (* x (+ 1.0 (/ 1.0 x))) (sqrt (cos x))) (+ x 1.0)) (/ (fmod x 1.0) (exp x))))
double code(double x) {
double tmp;
if (x <= -6e-309) {
tmp = fmod((x * (1.0 + (1.0 / x))), sqrt(cos(x))) / (x + 1.0);
} 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 <= (-6d-309)) then
tmp = mod((x * (1.0d0 + (1.0d0 / x))), sqrt(cos(x))) / (x + 1.0d0)
else
tmp = mod(x, 1.0d0) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -6e-309: tmp = math.fmod((x * (1.0 + (1.0 / x))), math.sqrt(math.cos(x))) / (x + 1.0) else: tmp = math.fmod(x, 1.0) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -6e-309) tmp = Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), sqrt(cos(x))) / Float64(x + 1.0)); else tmp = Float64(rem(x, 1.0) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -6e-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[(x + 1.0), $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 -6 \cdot 10^{-309}:\\
\;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(\sqrt{\cos x}\right)\right)}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -6.000000000000001e-309Initial program 6.8%
/-rgt-identity6.8%
associate-/r/6.7%
exp-neg6.8%
remove-double-neg6.8%
Simplified6.8%
Taylor expanded in x around 0 5.4%
+-commutative5.4%
Simplified5.4%
Taylor expanded in x around 0 6.1%
+-commutative5.4%
Simplified6.1%
Taylor expanded in x around inf 19.7%
if -6.000000000000001e-309 < x Initial program 3.6%
/-rgt-identity3.6%
associate-/r/3.6%
exp-neg3.6%
remove-double-neg3.6%
Simplified3.6%
Taylor expanded in x around 0 40.1%
+-commutative40.1%
Simplified40.1%
Taylor expanded in x around inf 99.9%
Taylor expanded in x around 0 99.9%
(FPCore (x) :precision binary64 (if (<= x -6e-309) (fmod (* x (+ 1.0 (/ 1.0 x))) 1.0) (/ (fmod x 1.0) (exp x))))
double code(double x) {
double tmp;
if (x <= -6e-309) {
tmp = fmod((x * (1.0 + (1.0 / x))), 1.0);
} 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 <= (-6d-309)) then
tmp = mod((x * (1.0d0 + (1.0d0 / x))), 1.0d0)
else
tmp = mod(x, 1.0d0) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -6e-309: tmp = math.fmod((x * (1.0 + (1.0 / x))), 1.0) else: tmp = math.fmod(x, 1.0) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -6e-309) tmp = rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), 1.0); else tmp = Float64(rem(x, 1.0) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -6e-309], N[With[{TMP1 = N[(x * N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = 1.0}, 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}
\mathbf{if}\;x \leq -6 \cdot 10^{-309}:\\
\;\;\;\;\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -6.000000000000001e-309Initial program 6.8%
/-rgt-identity6.8%
associate-/r/6.7%
exp-neg6.8%
remove-double-neg6.8%
Simplified6.8%
Taylor expanded in x around 0 6.8%
Taylor expanded in x around 0 4.8%
Taylor expanded in x around 0 4.7%
+-commutative5.4%
Simplified4.7%
Taylor expanded in x around inf 18.3%
if -6.000000000000001e-309 < x Initial program 3.6%
/-rgt-identity3.6%
associate-/r/3.6%
exp-neg3.6%
remove-double-neg3.6%
Simplified3.6%
Taylor expanded in x around 0 40.1%
+-commutative40.1%
Simplified40.1%
Taylor expanded in x around inf 99.9%
Taylor expanded in x around 0 99.9%
(FPCore (x) :precision binary64 (if (<= x -6e-309) (fmod (* x (+ 1.0 (/ 1.0 x))) 1.0) (fmod x 1.0)))
double code(double x) {
double tmp;
if (x <= -6e-309) {
tmp = fmod((x * (1.0 + (1.0 / x))), 1.0);
} else {
tmp = fmod(x, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-6d-309)) then
tmp = mod((x * (1.0d0 + (1.0d0 / x))), 1.0d0)
else
tmp = mod(x, 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -6e-309: tmp = math.fmod((x * (1.0 + (1.0 / x))), 1.0) else: tmp = math.fmod(x, 1.0) return tmp
function code(x) tmp = 0.0 if (x <= -6e-309) tmp = rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), 1.0); else tmp = rem(x, 1.0); end return tmp end
code[x_] := If[LessEqual[x, -6e-309], N[With[{TMP1 = N[(x * N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-309}:\\
\;\;\;\;\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \bmod 1\right)\\
\end{array}
\end{array}
if x < -6.000000000000001e-309Initial program 6.8%
/-rgt-identity6.8%
associate-/r/6.7%
exp-neg6.8%
remove-double-neg6.8%
Simplified6.8%
Taylor expanded in x around 0 6.8%
Taylor expanded in x around 0 4.8%
Taylor expanded in x around 0 4.7%
+-commutative5.4%
Simplified4.7%
Taylor expanded in x around inf 18.3%
if -6.000000000000001e-309 < x Initial program 3.6%
/-rgt-identity3.6%
associate-/r/3.6%
exp-neg3.6%
remove-double-neg3.6%
Simplified3.6%
Taylor expanded in x around 0 40.1%
+-commutative40.1%
Simplified40.1%
Taylor expanded in x around inf 99.9%
Taylor expanded in x around 0 99.9%
Taylor expanded in x around 0 98.6%
(FPCore (x) :precision binary64 (/ (fmod x 1.0) (+ x 1.0)))
double code(double x) {
return fmod(x, 1.0) / (x + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(x, 1.0d0) / (x + 1.0d0)
end function
def code(x): return math.fmod(x, 1.0) / (x + 1.0)
function code(x) return Float64(rem(x, 1.0) / Float64(x + 1.0)) end
code[x_] := N[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \bmod 1\right)}{x + 1}
\end{array}
Initial program 4.9%
/-rgt-identity4.9%
associate-/r/4.9%
exp-neg4.9%
remove-double-neg4.9%
Simplified4.9%
Taylor expanded in x around 0 25.8%
+-commutative25.8%
Simplified25.8%
Taylor expanded in x around inf 59.8%
Taylor expanded in x around 0 59.8%
Taylor expanded in x around 0 59.2%
+-commutative25.8%
Simplified59.2%
(FPCore (x) :precision binary64 (fmod x 1.0))
double code(double x) {
return fmod(x, 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(x, 1.0d0)
end function
def code(x): return math.fmod(x, 1.0)
function code(x) return rem(x, 1.0) end
code[x_] := N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(x \bmod 1\right)
\end{array}
Initial program 4.9%
/-rgt-identity4.9%
associate-/r/4.9%
exp-neg4.9%
remove-double-neg4.9%
Simplified4.9%
Taylor expanded in x around 0 25.8%
+-commutative25.8%
Simplified25.8%
Taylor expanded in x around inf 59.8%
Taylor expanded in x around 0 59.8%
Taylor expanded in x around 0 59.1%
(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 4.9%
/-rgt-identity4.9%
associate-/r/4.9%
exp-neg4.9%
remove-double-neg4.9%
Simplified4.9%
Taylor expanded in x around 0 4.9%
Taylor expanded in x around 0 4.1%
Taylor expanded in x around 0 24.8%
+-commutative25.8%
Simplified24.8%
Taylor expanded in x around 0 24.8%
herbie shell --seed 2024131
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))