
(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 7 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)
(/
(fmod
(+ x 1.0)
(sqrt
(+
(expm1 (log1p (* (cos x) 0.6666666666666666)))
(log (cbrt (exp (cos x)))))))
(+ x 1.0))
(/ (fmod (+ x 1.0) (sqrt (cos x))) (exp x))))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = fmod((x + 1.0), sqrt((expm1(log1p((cos(x) * 0.6666666666666666))) + log(cbrt(exp(cos(x))))))) / (x + 1.0);
} else {
tmp = fmod((x + 1.0), sqrt(cos(x))) / exp(x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = Float64(rem(Float64(x + 1.0), sqrt(Float64(expm1(log1p(Float64(cos(x) * 0.6666666666666666))) + log(cbrt(exp(cos(x))))))) / Float64(x + 1.0)); else tmp = Float64(rem(Float64(x + 1.0), sqrt(cos(x))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -5e-310], N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[Sqrt[N[(N[(Exp[N[Log[1 + N[(N[Cos[x], $MachinePrecision] * 0.6666666666666666), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] + N[Log[N[Power[N[Exp[N[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $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 = 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}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 5.1%
/-rgt-identity5.1%
associate-/r/5.1%
exp-neg5.1%
remove-double-neg5.1%
Simplified5.1%
add-log-exp5.1%
add-cube-cbrt97.9%
log-prod97.9%
pow297.9%
Applied egg-rr97.9%
expm1-log1p-u97.9%
expm1-undefine97.9%
log-pow97.9%
pow1/397.9%
log-pow97.9%
add-log-exp97.9%
Applied egg-rr97.9%
expm1-define97.9%
count-297.9%
distribute-rgt-out97.9%
metadata-eval97.9%
Simplified97.9%
Taylor expanded in x around 0 97.5%
+-commutative97.5%
Simplified97.5%
Taylor expanded in x around 0 98.1%
+-commutative97.5%
Simplified98.1%
if -4.999999999999985e-310 < x Initial program 5.2%
/-rgt-identity5.2%
associate-/r/5.2%
exp-neg5.2%
remove-double-neg5.2%
Simplified5.2%
Taylor expanded in x around 0 36.4%
+-commutative36.0%
Simplified36.4%
(FPCore (x)
:precision binary64
(/
(fmod
(+ x 1.0)
(sqrt
(+
(expm1 (log1p (* (cos x) 0.6666666666666666)))
(log (cbrt (exp (cos x)))))))
(exp x)))
double code(double x) {
return fmod((x + 1.0), sqrt((expm1(log1p((cos(x) * 0.6666666666666666))) + log(cbrt(exp(cos(x))))))) / exp(x);
}
function code(x) return Float64(rem(Float64(x + 1.0), sqrt(Float64(expm1(log1p(Float64(cos(x) * 0.6666666666666666))) + log(cbrt(exp(cos(x))))))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[Sqrt[N[(N[(Exp[N[Log[1 + N[(N[Cos[x], $MachinePrecision] * 0.6666666666666666), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] + N[Log[N[Power[N[Exp[N[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot 0.6666666666666666\right)\right) + \log \left(\sqrt[3]{e^{\cos x}}\right)}\right)\right)}{e^{x}}
\end{array}
Initial program 5.2%
/-rgt-identity5.2%
associate-/r/5.2%
exp-neg5.2%
remove-double-neg5.2%
Simplified5.2%
add-log-exp5.2%
add-cube-cbrt39.1%
log-prod39.1%
pow239.1%
Applied egg-rr39.1%
expm1-log1p-u39.1%
expm1-undefine39.0%
log-pow39.0%
pow1/339.1%
log-pow39.1%
add-log-exp39.1%
Applied egg-rr39.1%
expm1-define39.1%
count-239.1%
distribute-rgt-out39.1%
metadata-eval39.1%
Simplified39.1%
Taylor expanded in x around 0 58.6%
+-commutative58.6%
Simplified58.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))))
(if (<= x 100.0)
(/ (fmod (/ (pow E (+ x 1.0)) (pow (sqrt E) 2.0)) t_0) (exp x))
(/ (fmod (+ x 1.0) t_0) (exp x)))))
double code(double x) {
double t_0 = sqrt(cos(x));
double tmp;
if (x <= 100.0) {
tmp = fmod((pow(((double) M_E), (x + 1.0)) / pow(sqrt(((double) M_E)), 2.0)), t_0) / exp(x);
} else {
tmp = fmod((x + 1.0), t_0) / exp(x);
}
return tmp;
}
def code(x): t_0 = math.sqrt(math.cos(x)) tmp = 0 if x <= 100.0: tmp = math.fmod((math.pow(math.e, (x + 1.0)) / math.pow(math.sqrt(math.e), 2.0)), t_0) / math.exp(x) else: tmp = math.fmod((x + 1.0), t_0) / math.exp(x) return tmp
function code(x) t_0 = sqrt(cos(x)) tmp = 0.0 if (x <= 100.0) tmp = Float64(rem(Float64((exp(1) ^ Float64(x + 1.0)) / (sqrt(exp(1)) ^ 2.0)), t_0) / exp(x)); else tmp = Float64(rem(Float64(x + 1.0), t_0) / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 100.0], N[(N[With[{TMP1 = N[(N[Power[E, N[(x + 1.0), $MachinePrecision]], $MachinePrecision] / N[Power[N[Sqrt[E], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], 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 100:\\
\;\;\;\;\frac{\left(\left(\frac{{e}^{\left(x + 1\right)}}{{\left(\sqrt{e}\right)}^{2}}\right) \bmod t\_0\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod t\_0\right)}{e^{x}}\\
\end{array}
\end{array}
if x < 100Initial program 6.4%
/-rgt-identity6.4%
associate-/r/6.4%
exp-neg6.4%
remove-double-neg6.4%
Simplified6.4%
*-un-lft-identity6.4%
exp-prod6.4%
expm1-log1p-u6.4%
expm1-undefine6.4%
pow-sub6.4%
pow16.4%
Applied egg-rr6.4%
exp-1-e6.4%
log1p-undefine6.4%
rem-exp-log6.4%
+-commutative6.4%
exp-1-e6.4%
Simplified6.4%
add-sqr-sqrt48.2%
pow248.2%
Applied egg-rr48.2%
if 100 < 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.5%
+-commutative98.5%
Simplified98.5%
(FPCore (x) :precision binary64 (if (<= x 0.86) (/ (fmod (* x (+ 1.0 (/ 1.0 x))) (+ 1.0 (* -0.25 (pow x 2.0)))) (+ x 1.0)) (/ (fmod (+ x 1.0) (sqrt (cos x))) (exp x))))
double code(double x) {
double tmp;
if (x <= 0.86) {
tmp = fmod((x * (1.0 + (1.0 / x))), (1.0 + (-0.25 * pow(x, 2.0)))) / (x + 1.0);
} else {
tmp = fmod((x + 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.86d0) then
tmp = mod((x * (1.0d0 + (1.0d0 / x))), (1.0d0 + ((-0.25d0) * (x ** 2.0d0)))) / (x + 1.0d0)
else
tmp = mod((x + 1.0d0), sqrt(cos(x))) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= 0.86: tmp = math.fmod((x * (1.0 + (1.0 / x))), (1.0 + (-0.25 * math.pow(x, 2.0)))) / (x + 1.0) else: tmp = math.fmod((x + 1.0), math.sqrt(math.cos(x))) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= 0.86) tmp = Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), Float64(1.0 + Float64(-0.25 * (x ^ 2.0)))) / Float64(x + 1.0)); else tmp = Float64(rem(Float64(x + 1.0), sqrt(cos(x))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, 0.86], N[(N[With[{TMP1 = N[(x * N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = N[(1.0 + N[(-0.25 * N[Power[x, 2.0], $MachinePrecision]), $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 = 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.86:\\
\;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < 0.859999999999999987Initial program 6.4%
/-rgt-identity6.4%
associate-/r/6.4%
exp-neg6.4%
remove-double-neg6.4%
Simplified6.4%
Taylor expanded in x around 0 6.0%
+-commutative48.4%
Simplified6.0%
Taylor expanded in x around 0 6.3%
+-commutative48.4%
Simplified6.3%
Taylor expanded in x around 0 7.1%
Taylor expanded in x around inf 15.5%
if 0.859999999999999987 < 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.5%
+-commutative98.5%
Simplified98.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ 1.0 (* -0.25 (pow x 2.0)))))
(if (<= x 0.86)
(/ (fmod (* x (+ 1.0 (/ 1.0 x))) t_0) (+ x 1.0))
(/ (fmod (+ x 1.0) t_0) (exp x)))))
double code(double x) {
double t_0 = 1.0 + (-0.25 * pow(x, 2.0));
double tmp;
if (x <= 0.86) {
tmp = fmod((x * (1.0 + (1.0 / x))), t_0) / (x + 1.0);
} else {
tmp = fmod((x + 1.0), 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 = 1.0d0 + ((-0.25d0) * (x ** 2.0d0))
if (x <= 0.86d0) then
tmp = mod((x * (1.0d0 + (1.0d0 / x))), t_0) / (x + 1.0d0)
else
tmp = mod((x + 1.0d0), t_0) / exp(x)
end if
code = tmp
end function
def code(x): t_0 = 1.0 + (-0.25 * math.pow(x, 2.0)) tmp = 0 if x <= 0.86: tmp = math.fmod((x * (1.0 + (1.0 / x))), t_0) / (x + 1.0) else: tmp = math.fmod((x + 1.0), t_0) / math.exp(x) return tmp
function code(x) t_0 = Float64(1.0 + Float64(-0.25 * (x ^ 2.0))) tmp = 0.0 if (x <= 0.86) tmp = Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), t_0) / Float64(x + 1.0)); else tmp = Float64(rem(Float64(x + 1.0), t_0) / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[(1.0 + N[(-0.25 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 0.86], 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 = N[(x + 1.0), $MachinePrecision], 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 := 1 + -0.25 \cdot {x}^{2}\\
\mathbf{if}\;x \leq 0.86:\\
\;\;\;\;\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod t\_0\right)}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod t\_0\right)}{e^{x}}\\
\end{array}
\end{array}
if x < 0.859999999999999987Initial program 6.4%
/-rgt-identity6.4%
associate-/r/6.4%
exp-neg6.4%
remove-double-neg6.4%
Simplified6.4%
Taylor expanded in x around 0 6.0%
+-commutative48.4%
Simplified6.0%
Taylor expanded in x around 0 6.3%
+-commutative48.4%
Simplified6.3%
Taylor expanded in x around 0 7.1%
Taylor expanded in x around inf 15.5%
if 0.859999999999999987 < 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 0.3%
Taylor expanded in x around 0 98.3%
+-commutative98.5%
Simplified98.3%
(FPCore (x) :precision binary64 (/ (fmod (* x (+ 1.0 (/ 1.0 x))) (+ 1.0 (* -0.25 (pow x 2.0)))) (+ x 1.0)))
double code(double x) {
return fmod((x * (1.0 + (1.0 / x))), (1.0 + (-0.25 * pow(x, 2.0)))) / (x + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod((x * (1.0d0 + (1.0d0 / x))), (1.0d0 + ((-0.25d0) * (x ** 2.0d0)))) / (x + 1.0d0)
end function
def code(x): return math.fmod((x * (1.0 + (1.0 / x))), (1.0 + (-0.25 * math.pow(x, 2.0)))) / (x + 1.0)
function code(x) return Float64(rem(Float64(x * Float64(1.0 + Float64(1.0 / x))), Float64(1.0 + Float64(-0.25 * (x ^ 2.0)))) / Float64(x + 1.0)) end
code[x_] := N[(N[With[{TMP1 = N[(x * N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = N[(1.0 + N[(-0.25 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(x \cdot \left(1 + \frac{1}{x}\right)\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{x + 1}
\end{array}
Initial program 5.2%
/-rgt-identity5.2%
associate-/r/5.2%
exp-neg5.2%
remove-double-neg5.2%
Simplified5.2%
Taylor expanded in x around 0 4.8%
+-commutative58.6%
Simplified4.8%
Taylor expanded in x around 0 6.2%
+-commutative58.6%
Simplified6.2%
Taylor expanded in x around 0 6.3%
Taylor expanded in x around inf 13.0%
(FPCore (x) :precision binary64 (/ (fmod (+ x 1.0) (+ 1.0 (* -0.25 (* x x)))) (+ x 1.0)))
double code(double x) {
return fmod((x + 1.0), (1.0 + (-0.25 * (x * x)))) / (x + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod((x + 1.0d0), (1.0d0 + ((-0.25d0) * (x * x)))) / (x + 1.0d0)
end function
def code(x): return math.fmod((x + 1.0), (1.0 + (-0.25 * (x * x)))) / (x + 1.0)
function code(x) return Float64(rem(Float64(x + 1.0), Float64(1.0 + Float64(-0.25 * Float64(x * x)))) / Float64(x + 1.0)) end
code[x_] := N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[(1.0 + N[(-0.25 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(x + 1\right) \bmod \left(1 + -0.25 \cdot \left(x \cdot x\right)\right)\right)}{x + 1}
\end{array}
Initial program 5.2%
/-rgt-identity5.2%
associate-/r/5.2%
exp-neg5.2%
remove-double-neg5.2%
Simplified5.2%
Taylor expanded in x around 0 4.8%
+-commutative58.6%
Simplified4.8%
Taylor expanded in x around 0 6.2%
+-commutative58.6%
Simplified6.2%
Taylor expanded in x around 0 6.3%
unpow26.3%
Applied egg-rr6.3%
herbie shell --seed 2024179
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))