
(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 -1e-310)
(/
(fmod
(+ 1.0 (* x (+ 1.0 (* x 0.5))))
(sqrt (+ (log (pow (cbrt E) 2.0)) (log (cbrt E)))))
(exp x))
(/ (fmod (+ x 1.0) 1.0) (exp x))))
double code(double x) {
double tmp;
if (x <= -1e-310) {
tmp = fmod((1.0 + (x * (1.0 + (x * 0.5)))), sqrt((log(pow(cbrt(((double) M_E)), 2.0)) + log(cbrt(((double) M_E)))))) / exp(x);
} else {
tmp = fmod((x + 1.0), 1.0) / exp(x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1e-310) tmp = Float64(rem(Float64(1.0 + Float64(x * Float64(1.0 + Float64(x * 0.5)))), sqrt(Float64(log((cbrt(exp(1)) ^ 2.0)) + log(cbrt(exp(1)))))) / exp(x)); else tmp = Float64(rem(Float64(x + 1.0), 1.0) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -1e-310], N[(N[With[{TMP1 = N[(1.0 + N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = N[Sqrt[N[(N[Log[N[Power[N[Power[E, 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 = N[(x + 1.0), $MachinePrecision], 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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{\left(\left(1 + x \cdot \left(1 + x \cdot 0.5\right)\right) \bmod \left(\sqrt{\log \left({\left(\sqrt[3]{e}\right)}^{2}\right) + \log \left(\sqrt[3]{e}\right)}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -9.999999999999969e-311Initial program 5.7%
/-rgt-identity5.7%
associate-/r/5.7%
exp-neg5.7%
remove-double-neg5.7%
Simplified5.7%
add-log-exp5.7%
add-cube-cbrt98.2%
log-prod98.2%
pow298.2%
Applied egg-rr98.2%
Taylor expanded in x around 0 98.2%
exp-1-e98.2%
Simplified98.2%
Taylor expanded in x around 0 98.2%
*-commutative98.2%
Simplified98.2%
Taylor expanded in x around 0 98.2%
exp-1-e98.2%
Simplified98.2%
if -9.999999999999969e-311 < x Initial program 4.1%
/-rgt-identity4.1%
associate-/r/4.1%
exp-neg4.1%
remove-double-neg4.1%
Simplified4.1%
Taylor expanded in x around 0 4.0%
Taylor expanded in x around 0 38.8%
+-commutative38.8%
Simplified38.8%
(FPCore (x) :precision binary64 (/ (fmod (* x (+ 1.0 (/ 1.0 x))) (sqrt (cos x))) (exp x)))
double code(double x) {
return fmod((x * (1.0 + (1.0 / x))), sqrt(cos(x))) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod((x * (1.0d0 + (1.0d0 / x))), sqrt(cos(x))) / exp(x)
end function
def code(x): return math.fmod((x * (1.0 + (1.0 / x))), math.sqrt(math.cos(x))) / math.exp(x)
function code(x) return Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), sqrt(cos(x))) / exp(x)) end
code[x_] := 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[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}
\end{array}
Initial program 4.8%
/-rgt-identity4.8%
associate-/r/4.8%
exp-neg4.8%
remove-double-neg4.8%
Simplified4.8%
Taylor expanded in x around 0 24.6%
+-commutative24.6%
Simplified24.6%
Taylor expanded in x around inf 33.1%
(FPCore (x) :precision binary64 (if (<= x -1e-303) (/ (fmod (* x (+ 1.0 (/ 1.0 x))) (sqrt (cos x))) (+ x 1.0)) (/ (fmod (+ x 1.0) 1.0) (exp x))))
double code(double x) {
double tmp;
if (x <= -1e-303) {
tmp = fmod((x * (1.0 + (1.0 / x))), sqrt(cos(x))) / (x + 1.0);
} else {
tmp = fmod((x + 1.0), 1.0) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1d-303)) then
tmp = mod((x * (1.0d0 + (1.0d0 / x))), sqrt(cos(x))) / (x + 1.0d0)
else
tmp = mod((x + 1.0d0), 1.0d0) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -1e-303: tmp = math.fmod((x * (1.0 + (1.0 / x))), math.sqrt(math.cos(x))) / (x + 1.0) else: tmp = math.fmod((x + 1.0), 1.0) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -1e-303) tmp = Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), sqrt(cos(x))) / Float64(x + 1.0)); else tmp = Float64(rem(Float64(x + 1.0), 1.0) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -1e-303], 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 = N[(x + 1.0), $MachinePrecision], 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 -1 \cdot 10^{-303}:\\
\;\;\;\;\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(\left(x + 1\right) \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -9.99999999999999931e-304Initial program 5.7%
/-rgt-identity5.7%
associate-/r/5.7%
exp-neg5.8%
remove-double-neg5.8%
Simplified5.8%
Taylor expanded in x around 0 5.5%
+-commutative5.5%
Simplified5.5%
Taylor expanded in x around 0 6.0%
+-commutative5.5%
Simplified6.0%
Taylor expanded in x around inf 26.3%
if -9.99999999999999931e-304 < x Initial program 4.1%
/-rgt-identity4.1%
associate-/r/4.1%
exp-neg4.1%
remove-double-neg4.1%
Simplified4.1%
Taylor expanded in x around 0 4.0%
Taylor expanded in x around 0 38.6%
+-commutative38.6%
Simplified38.6%
(FPCore (x) :precision binary64 (fmod (* x (+ 1.0 (/ 1.0 x))) 1.0))
double code(double x) {
return fmod((x * (1.0 + (1.0 / x))), 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod((x * (1.0d0 + (1.0d0 / x))), 1.0d0)
end function
def code(x): return math.fmod((x * (1.0 + (1.0 / x))), 1.0)
function code(x) return rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), 1.0) end
code[x_] := 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]
\begin{array}{l}
\\
\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod 1\right)
\end{array}
Initial program 4.8%
/-rgt-identity4.8%
associate-/r/4.8%
exp-neg4.8%
remove-double-neg4.8%
Simplified4.8%
Taylor expanded in x around 0 4.7%
Taylor expanded in x around 0 4.2%
Taylor expanded in x around 0 23.3%
+-commutative24.6%
Simplified23.3%
Taylor expanded in x around inf 31.8%
(FPCore (x) :precision binary64 (/ (fmod (+ x 1.0) 1.0) (+ x 1.0)))
double code(double x) {
return fmod((x + 1.0), 1.0) / (x + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod((x + 1.0d0), 1.0d0) / (x + 1.0d0)
end function
def code(x): return math.fmod((x + 1.0), 1.0) / (x + 1.0)
function code(x) return Float64(rem(Float64(x + 1.0), 1.0) / Float64(x + 1.0)) end
code[x_] := N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(x + 1\right) \bmod 1\right)}{x + 1}
\end{array}
Initial program 4.8%
/-rgt-identity4.8%
associate-/r/4.8%
exp-neg4.8%
remove-double-neg4.8%
Simplified4.8%
Taylor expanded in x around 0 24.6%
+-commutative24.6%
Simplified24.6%
Taylor expanded in x around 0 5.9%
+-commutative24.6%
Simplified5.9%
Taylor expanded in x around 0 24.0%
(FPCore (x) :precision binary64 (fmod (+ x 1.0) 1.0))
double code(double x) {
return fmod((x + 1.0), 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod((x + 1.0d0), 1.0d0)
end function
def code(x): return math.fmod((x + 1.0), 1.0)
function code(x) return rem(Float64(x + 1.0), 1.0) end
code[x_] := N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x + 1\right) \bmod 1\right)
\end{array}
Initial program 4.8%
/-rgt-identity4.8%
associate-/r/4.8%
exp-neg4.8%
remove-double-neg4.8%
Simplified4.8%
Taylor expanded in x around 0 4.7%
Taylor expanded in x around 0 4.2%
Taylor expanded in x around 0 23.3%
+-commutative24.6%
Simplified23.3%
herbie shell --seed 2024135
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))