
(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
(let* ((t_0 (exp (- x)))
(t_1 (sqrt (cos x)))
(t_2 (* t_0 (fmod (exp x) t_1))))
(if (or (<= t_2 0.0) (not (<= t_2 2.0)))
t_0
(/ (fmod (exp x) (* 2.0 (* t_1 (cbrt 0.125)))) (exp x)))))
double code(double x) {
double t_0 = exp(-x);
double t_1 = sqrt(cos(x));
double t_2 = t_0 * fmod(exp(x), t_1);
double tmp;
if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
tmp = t_0;
} else {
tmp = fmod(exp(x), (2.0 * (t_1 * cbrt(0.125)))) / exp(x);
}
return tmp;
}
function code(x) t_0 = exp(Float64(-x)) t_1 = sqrt(cos(x)) t_2 = Float64(t_0 * rem(exp(x), t_1)) tmp = 0.0 if ((t_2 <= 0.0) || !(t_2 <= 2.0)) tmp = t_0; else tmp = Float64(rem(exp(x), Float64(2.0 * Float64(t_1 * cbrt(0.125)))) / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$1}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$2, 0.0], N[Not[LessEqual[t$95$2, 2.0]], $MachinePrecision]], t$95$0, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(2.0 * N[(t$95$1 * N[Power[0.125, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := \sqrt{\cos x}\\
t_2 := t\_0 \cdot \left(\left(e^{x}\right) \bmod t\_1\right)\\
\mathbf{if}\;t\_2 \leq 0 \lor \neg \left(t\_2 \leq 2\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(2 \cdot \left(t\_1 \cdot \sqrt[3]{0.125}\right)\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 3.3%
/-rgt-identity3.3%
associate-/r/3.3%
exp-neg3.3%
remove-double-neg3.3%
Simplified3.3%
add-exp-log3.3%
div-exp3.3%
Applied egg-rr3.3%
Taylor expanded in x around inf 63.6%
neg-mul-163.6%
Simplified63.6%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 79.2%
/-rgt-identity79.2%
associate-/r/79.2%
exp-neg79.4%
remove-double-neg79.4%
Simplified79.4%
add-log-exp79.3%
add-sqr-sqrt79.0%
log-prod79.9%
Applied egg-rr79.9%
count-279.9%
Simplified79.9%
add-cbrt-cube78.6%
pow378.6%
pow1/278.6%
log-pow78.6%
add-log-exp78.6%
Applied egg-rr78.6%
pow1/379.4%
unpow-prod-down79.4%
unpow-prod-down79.4%
metadata-eval79.4%
pow379.4%
pow1/378.9%
add-cbrt-cube79.4%
Applied egg-rr79.4%
*-commutative79.4%
unpow1/380.4%
Simplified80.4%
Final simplification64.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))) (t_1 (* t_0 (fmod (exp x) (sqrt (cos x))))))
(if (or (<= t_1 0.0) (not (<= t_1 2.0)))
t_0
(/ (fmod (exp x) (pow (pow (cos x) 0.16666666666666666) 3.0)) (exp x)))))
double code(double x) {
double t_0 = exp(-x);
double t_1 = t_0 * fmod(exp(x), sqrt(cos(x)));
double tmp;
if ((t_1 <= 0.0) || !(t_1 <= 2.0)) {
tmp = t_0;
} else {
tmp = fmod(exp(x), pow(pow(cos(x), 0.16666666666666666), 3.0)) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = exp(-x)
t_1 = t_0 * mod(exp(x), sqrt(cos(x)))
if ((t_1 <= 0.0d0) .or. (.not. (t_1 <= 2.0d0))) then
tmp = t_0
else
tmp = mod(exp(x), ((cos(x) ** 0.16666666666666666d0) ** 3.0d0)) / exp(x)
end if
code = tmp
end function
def code(x): t_0 = math.exp(-x) t_1 = t_0 * math.fmod(math.exp(x), math.sqrt(math.cos(x))) tmp = 0 if (t_1 <= 0.0) or not (t_1 <= 2.0): tmp = t_0 else: tmp = math.fmod(math.exp(x), math.pow(math.pow(math.cos(x), 0.16666666666666666), 3.0)) / math.exp(x) return tmp
function code(x) t_0 = exp(Float64(-x)) t_1 = Float64(t_0 * rem(exp(x), sqrt(cos(x)))) tmp = 0.0 if ((t_1 <= 0.0) || !(t_1 <= 2.0)) tmp = t_0; else tmp = Float64(rem(exp(x), ((cos(x) ^ 0.16666666666666666) ^ 3.0)) / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 0.0], N[Not[LessEqual[t$95$1, 2.0]], $MachinePrecision]], t$95$0, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 0.16666666666666666], $MachinePrecision], 3.0], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := t\_0 \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;t\_1 \leq 0 \lor \neg \left(t\_1 \leq 2\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left({\left({\cos x}^{0.16666666666666666}\right)}^{3}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 3.3%
/-rgt-identity3.3%
associate-/r/3.3%
exp-neg3.3%
remove-double-neg3.3%
Simplified3.3%
add-exp-log3.3%
div-exp3.3%
Applied egg-rr3.3%
Taylor expanded in x around inf 63.6%
neg-mul-163.6%
Simplified63.6%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 79.2%
/-rgt-identity79.2%
associate-/r/79.2%
exp-neg79.4%
remove-double-neg79.4%
Simplified79.4%
add-cube-cbrt77.8%
associate-*l*77.8%
cbrt-prod78.2%
add-sqr-sqrt78.5%
pow1/378.7%
pow1/278.7%
pow-pow78.7%
metadata-eval78.7%
Applied egg-rr78.7%
unpow1/379.4%
metadata-eval79.4%
pow-sqr79.9%
cube-mult79.9%
Simplified79.9%
Final simplification64.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))) (t_1 (* t_0 (fmod (exp x) (sqrt (cos x))))))
(if (or (<= t_1 0.0) (not (<= t_1 2.0)))
t_0
(/ (fmod (exp x) (cbrt (pow (cos x) 1.5))) (exp x)))))
double code(double x) {
double t_0 = exp(-x);
double t_1 = t_0 * fmod(exp(x), sqrt(cos(x)));
double tmp;
if ((t_1 <= 0.0) || !(t_1 <= 2.0)) {
tmp = t_0;
} else {
tmp = fmod(exp(x), cbrt(pow(cos(x), 1.5))) / exp(x);
}
return tmp;
}
function code(x) t_0 = exp(Float64(-x)) t_1 = Float64(t_0 * rem(exp(x), sqrt(cos(x)))) tmp = 0.0 if ((t_1 <= 0.0) || !(t_1 <= 2.0)) tmp = t_0; else tmp = Float64(rem(exp(x), cbrt((cos(x) ^ 1.5))) / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 0.0], N[Not[LessEqual[t$95$1, 2.0]], $MachinePrecision]], t$95$0, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := t\_0 \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;t\_1 \leq 0 \lor \neg \left(t\_1 \leq 2\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt[3]{{\cos x}^{1.5}}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 3.3%
/-rgt-identity3.3%
associate-/r/3.3%
exp-neg3.3%
remove-double-neg3.3%
Simplified3.3%
add-exp-log3.3%
div-exp3.3%
Applied egg-rr3.3%
Taylor expanded in x around inf 63.6%
neg-mul-163.6%
Simplified63.6%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 79.2%
/-rgt-identity79.2%
associate-/r/79.2%
exp-neg79.4%
remove-double-neg79.4%
Simplified79.4%
add-cbrt-cube78.9%
pow378.9%
pow1/278.9%
pow-pow79.6%
metadata-eval79.6%
Applied egg-rr79.6%
Final simplification64.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x)))
(t_1 (fmod (exp x) (sqrt (cos x))))
(t_2 (* t_0 t_1)))
(if (or (<= t_2 0.0) (not (<= t_2 2.0))) t_0 (/ t_1 (exp x)))))
double code(double x) {
double t_0 = exp(-x);
double t_1 = fmod(exp(x), sqrt(cos(x)));
double t_2 = t_0 * t_1;
double tmp;
if ((t_2 <= 0.0) || !(t_2 <= 2.0)) {
tmp = t_0;
} else {
tmp = t_1 / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = exp(-x)
t_1 = mod(exp(x), sqrt(cos(x)))
t_2 = t_0 * t_1
if ((t_2 <= 0.0d0) .or. (.not. (t_2 <= 2.0d0))) then
tmp = t_0
else
tmp = t_1 / exp(x)
end if
code = tmp
end function
def code(x): t_0 = math.exp(-x) t_1 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_2 = t_0 * t_1 tmp = 0 if (t_2 <= 0.0) or not (t_2 <= 2.0): tmp = t_0 else: tmp = t_1 / math.exp(x) return tmp
function code(x) t_0 = exp(Float64(-x)) t_1 = rem(exp(x), sqrt(cos(x))) t_2 = Float64(t_0 * t_1) tmp = 0.0 if ((t_2 <= 0.0) || !(t_2 <= 2.0)) tmp = t_0; else tmp = Float64(t_1 / exp(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1), $MachinePrecision]}, If[Or[LessEqual[t$95$2, 0.0], N[Not[LessEqual[t$95$2, 2.0]], $MachinePrecision]], t$95$0, N[(t$95$1 / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_2 := t\_0 \cdot t\_1\\
\mathbf{if}\;t\_2 \leq 0 \lor \neg \left(t\_2 \leq 2\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{e^{x}}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0 or 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 3.3%
/-rgt-identity3.3%
associate-/r/3.3%
exp-neg3.3%
remove-double-neg3.3%
Simplified3.3%
add-exp-log3.3%
div-exp3.3%
Applied egg-rr3.3%
Taylor expanded in x around inf 63.6%
neg-mul-163.6%
Simplified63.6%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 79.2%
/-rgt-identity79.2%
associate-/r/79.2%
exp-neg79.4%
remove-double-neg79.4%
Simplified79.4%
Final simplification64.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (exp (sqrt (cos x))))))
(if (<= x 0.1)
(/ (fmod (exp x) (+ (log (pow t_0 2.0)) (log t_0))) (exp x))
(exp (- x)))))
double code(double x) {
double t_0 = cbrt(exp(sqrt(cos(x))));
double tmp;
if (x <= 0.1) {
tmp = fmod(exp(x), (log(pow(t_0, 2.0)) + log(t_0))) / exp(x);
} else {
tmp = exp(-x);
}
return tmp;
}
function code(x) t_0 = cbrt(exp(sqrt(cos(x)))) tmp = 0.0 if (x <= 0.1) tmp = Float64(rem(exp(x), Float64(log((t_0 ^ 2.0)) + log(t_0))) / exp(x)); else tmp = exp(Float64(-x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[Exp[N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[x, 0.1], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Log[N[Power[t$95$0, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$0], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[Exp[(-x)], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{e^{\sqrt{\cos x}}}\\
\mathbf{if}\;x \leq 0.1:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\log \left({t\_0}^{2}\right) + \log t\_0\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < 0.10000000000000001Initial program 8.4%
/-rgt-identity8.4%
associate-/r/8.4%
exp-neg8.4%
remove-double-neg8.4%
Simplified8.4%
add-log-exp8.4%
add-cube-cbrt54.4%
log-prod54.3%
pow254.3%
Applied egg-rr54.3%
if 0.10000000000000001 < x Initial program 0.0%
/-rgt-identity0.0%
associate-/r/0.0%
exp-neg0.0%
remove-double-neg0.0%
Simplified0.0%
add-exp-log0.0%
div-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
Final simplification64.1%
(FPCore (x) :precision binary64 (exp (- x)))
double code(double x) {
return exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(-x)
end function
public static double code(double x) {
return Math.exp(-x);
}
def code(x): return math.exp(-x)
function code(x) return exp(Float64(-x)) end
function tmp = code(x) tmp = exp(-x); end
code[x_] := N[Exp[(-x)], $MachinePrecision]
\begin{array}{l}
\\
e^{-x}
\end{array}
Initial program 6.6%
/-rgt-identity6.6%
associate-/r/6.6%
exp-neg6.6%
remove-double-neg6.6%
Simplified6.6%
add-exp-log6.6%
div-exp6.6%
Applied egg-rr6.6%
Taylor expanded in x around inf 62.3%
neg-mul-162.3%
Simplified62.3%
Final simplification62.3%
herbie shell --seed 2024079
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))