
(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 5 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 (fmod (exp x) (sqrt (cos x))))
(t_1 (exp (- x)))
(t_2 (* t_0 t_1)))
(if (<= t_2 0.0) (exp x) (if (<= t_2 2.0) (/ 1.0 (/ (exp x) t_0)) t_1))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double t_1 = exp(-x);
double t_2 = t_0 * t_1;
double tmp;
if (t_2 <= 0.0) {
tmp = exp(x);
} else if (t_2 <= 2.0) {
tmp = 1.0 / (exp(x) / t_0);
} else {
tmp = t_1;
}
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 = mod(exp(x), sqrt(cos(x)))
t_1 = exp(-x)
t_2 = t_0 * t_1
if (t_2 <= 0.0d0) then
tmp = exp(x)
else if (t_2 <= 2.0d0) then
tmp = 1.0d0 / (exp(x) / t_0)
else
tmp = t_1
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_1 = math.exp(-x) t_2 = t_0 * t_1 tmp = 0 if t_2 <= 0.0: tmp = math.exp(x) elif t_2 <= 2.0: tmp = 1.0 / (math.exp(x) / t_0) else: tmp = t_1 return tmp
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) t_1 = exp(Float64(-x)) t_2 = Float64(t_0 * t_1) tmp = 0.0 if (t_2 <= 0.0) tmp = exp(x); elseif (t_2 <= 2.0) tmp = Float64(1.0 / Float64(exp(x) / t_0)); else tmp = t_1; end return tmp end
code[x_] := Block[{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]}, Block[{t$95$1 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, 0.0], N[Exp[x], $MachinePrecision], If[LessEqual[t$95$2, 2.0], N[(1.0 / N[(N[Exp[x], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_1 := e^{-x}\\
t_2 := t\_0 \cdot t\_1\\
\mathbf{if}\;t\_2 \leq 0:\\
\;\;\;\;e^{x}\\
\mathbf{elif}\;t\_2 \leq 2:\\
\;\;\;\;\frac{1}{\frac{e^{x}}{t\_0}}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0Initial program 4.1%
/-rgt-identity4.1%
associate-/r/4.1%
exp-neg4.1%
remove-double-neg4.1%
Simplified4.1%
add-cbrt-cube4.1%
pow1/34.1%
pow-to-exp4.1%
pow34.1%
log-pow4.1%
log-div4.1%
add-log-exp4.1%
Applied egg-rr4.1%
Taylor expanded in x around inf 58.8%
neg-mul-158.8%
Simplified58.8%
*-commutative58.8%
associate-*r*58.8%
metadata-eval58.8%
*-un-lft-identity58.8%
add-sqr-sqrt56.5%
sqrt-unprod58.8%
sqr-neg58.8%
sqrt-unprod2.2%
add-sqr-sqrt58.8%
add-log-exp58.8%
*-un-lft-identity58.8%
log-prod58.8%
metadata-eval58.8%
add-log-exp58.8%
Applied egg-rr58.8%
+-lft-identity58.8%
Simplified58.8%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 78.9%
/-rgt-identity78.9%
associate-/r/78.8%
exp-neg79.1%
remove-double-neg79.1%
Simplified79.1%
add-exp-log79.1%
div-exp79.0%
Applied egg-rr79.0%
exp-diff79.1%
add-exp-log79.1%
clear-num79.1%
Applied egg-rr79.1%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 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 simplification68.1%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))) (t_1 (cbrt (exp t_0))) (t_2 (exp (- x))))
(if (<= (* (fmod (exp x) t_0) t_2) 2.0)
(/ (fmod (exp x) (+ (log (pow t_1 2.0)) (log t_1))) (exp x))
t_2)))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = cbrt(exp(t_0));
double t_2 = exp(-x);
double tmp;
if ((fmod(exp(x), t_0) * t_2) <= 2.0) {
tmp = fmod(exp(x), (log(pow(t_1, 2.0)) + log(t_1))) / exp(x);
} else {
tmp = t_2;
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) t_1 = cbrt(exp(t_0)) t_2 = exp(Float64(-x)) tmp = 0.0 if (Float64(rem(exp(x), t_0) * t_2) <= 2.0) tmp = Float64(rem(exp(x), Float64(log((t_1 ^ 2.0)) + log(t_1))) / exp(x)); else tmp = t_2; end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Exp[t$95$0], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$2), $MachinePrecision], 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Log[N[Power[t$95$1, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$1], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := \sqrt[3]{e^{t\_0}}\\
t_2 := e^{-x}\\
\mathbf{if}\;\left(\left(e^{x}\right) \bmod t\_0\right) \cdot t\_2 \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\log \left({t\_1}^{2}\right) + \log t\_1\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.2%
/-rgt-identity9.2%
associate-/r/9.2%
exp-neg9.2%
remove-double-neg9.2%
Simplified9.2%
add-log-exp9.2%
add-cube-cbrt59.9%
log-prod59.9%
pow259.9%
Applied egg-rr59.9%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 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 simplification67.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (fmod (exp x) (sqrt (cos x))))
(t_1 (exp (- x)))
(t_2 (* t_0 t_1)))
(if (<= t_2 0.0) (exp x) (if (<= t_2 2.0) (/ t_0 (exp x)) t_1))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double t_1 = exp(-x);
double t_2 = t_0 * t_1;
double tmp;
if (t_2 <= 0.0) {
tmp = exp(x);
} else if (t_2 <= 2.0) {
tmp = t_0 / exp(x);
} else {
tmp = t_1;
}
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 = mod(exp(x), sqrt(cos(x)))
t_1 = exp(-x)
t_2 = t_0 * t_1
if (t_2 <= 0.0d0) then
tmp = exp(x)
else if (t_2 <= 2.0d0) then
tmp = t_0 / exp(x)
else
tmp = t_1
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) t_1 = math.exp(-x) t_2 = t_0 * t_1 tmp = 0 if t_2 <= 0.0: tmp = math.exp(x) elif t_2 <= 2.0: tmp = t_0 / math.exp(x) else: tmp = t_1 return tmp
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) t_1 = exp(Float64(-x)) t_2 = Float64(t_0 * t_1) tmp = 0.0 if (t_2 <= 0.0) tmp = exp(x); elseif (t_2 <= 2.0) tmp = Float64(t_0 / exp(x)); else tmp = t_1; end return tmp end
code[x_] := Block[{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]}, Block[{t$95$1 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, 0.0], N[Exp[x], $MachinePrecision], If[LessEqual[t$95$2, 2.0], N[(t$95$0 / N[Exp[x], $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_1 := e^{-x}\\
t_2 := t\_0 \cdot t\_1\\
\mathbf{if}\;t\_2 \leq 0:\\
\;\;\;\;e^{x}\\
\mathbf{elif}\;t\_2 \leq 2:\\
\;\;\;\;\frac{t\_0}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0Initial program 4.1%
/-rgt-identity4.1%
associate-/r/4.1%
exp-neg4.1%
remove-double-neg4.1%
Simplified4.1%
add-cbrt-cube4.1%
pow1/34.1%
pow-to-exp4.1%
pow34.1%
log-pow4.1%
log-div4.1%
add-log-exp4.1%
Applied egg-rr4.1%
Taylor expanded in x around inf 58.8%
neg-mul-158.8%
Simplified58.8%
*-commutative58.8%
associate-*r*58.8%
metadata-eval58.8%
*-un-lft-identity58.8%
add-sqr-sqrt56.5%
sqrt-unprod58.8%
sqr-neg58.8%
sqrt-unprod2.2%
add-sqr-sqrt58.8%
add-log-exp58.8%
*-un-lft-identity58.8%
log-prod58.8%
metadata-eval58.8%
add-log-exp58.8%
Applied egg-rr58.8%
+-lft-identity58.8%
Simplified58.8%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 78.9%
/-rgt-identity78.9%
associate-/r/78.8%
exp-neg79.1%
remove-double-neg79.1%
Simplified79.1%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 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 simplification68.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 7.4%
/-rgt-identity7.4%
associate-/r/7.3%
exp-neg7.4%
remove-double-neg7.4%
Simplified7.4%
add-exp-log7.4%
div-exp7.4%
Applied egg-rr7.4%
Taylor expanded in x around inf 65.2%
neg-mul-165.2%
Simplified65.2%
Final simplification65.2%
(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(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 7.4%
/-rgt-identity7.4%
associate-/r/7.3%
exp-neg7.4%
remove-double-neg7.4%
Simplified7.4%
add-cbrt-cube7.4%
pow1/37.4%
pow-to-exp7.4%
pow37.4%
log-pow7.4%
log-div7.4%
add-log-exp7.4%
Applied egg-rr7.4%
Taylor expanded in x around inf 65.2%
neg-mul-165.2%
Simplified65.2%
*-commutative65.2%
associate-*r*65.2%
metadata-eval65.2%
*-un-lft-identity65.2%
add-sqr-sqrt43.2%
sqrt-unprod45.5%
sqr-neg45.5%
sqrt-unprod2.4%
add-sqr-sqrt45.5%
add-log-exp45.5%
*-un-lft-identity45.5%
log-prod45.5%
metadata-eval45.5%
add-log-exp45.5%
Applied egg-rr45.5%
+-lft-identity45.5%
Simplified45.5%
Final simplification45.5%
herbie shell --seed 2024055
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))