
(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 (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
(+ 1.0 (expm1 (- (log t_1) 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 = 1.0 + expm1((log(t_1) - x));
}
return tmp;
}
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 = 1.0 + math.expm1((math.log(t_1) - 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(1.0 + expm1(Float64(log(t_1) - 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[(1.0 + N[(Exp[N[(N[Log[t$95$1], $MachinePrecision] - x), $MachinePrecision]] - 1), $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}:\\
\;\;\;\;1 + \mathsf{expm1}\left(\log t\_1 - x\right)\\
\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-cbrt-cube3.3%
pow1/33.3%
pow-to-exp3.3%
pow33.3%
log-pow3.3%
log-div3.3%
add-log-exp3.3%
Applied egg-rr3.3%
Taylor expanded in x around inf 62.2%
neg-mul-162.2%
Simplified62.2%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 71.0%
/-rgt-identity71.0%
associate-/r/70.9%
exp-neg71.1%
remove-double-neg71.1%
Simplified71.1%
add-cbrt-cube71.0%
pow1/371.1%
pow-to-exp71.1%
pow371.1%
log-pow71.1%
log-div71.1%
add-log-exp71.1%
Applied egg-rr71.1%
add-log-exp71.3%
Applied egg-rr71.3%
*-commutative71.3%
associate-*r*71.4%
metadata-eval71.4%
*-un-lft-identity71.4%
rem-log-exp71.0%
log1p-expm1-u71.2%
log1p-undefine71.2%
rem-exp-log71.3%
log1p-expm1-u71.3%
+-commutative71.3%
Applied egg-rr71.3%
Final simplification62.7%
(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 (/ 1.0 (/ (exp x) t_1)))))
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 = 1.0 / (exp(x) / 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 = 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 = 1.0d0 / (exp(x) / t_1)
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 = 1.0 / (math.exp(x) / t_1) 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(1.0 / Float64(exp(x) / t_1)); 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[(1.0 / N[(N[Exp[x], $MachinePrecision] / t$95$1), $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{1}{\frac{e^{x}}{t\_1}}\\
\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-cbrt-cube3.3%
pow1/33.3%
pow-to-exp3.3%
pow33.3%
log-pow3.3%
log-div3.3%
add-log-exp3.3%
Applied egg-rr3.3%
Taylor expanded in x around inf 62.2%
neg-mul-162.2%
Simplified62.2%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 71.0%
/-rgt-identity71.0%
associate-/r/70.9%
exp-neg71.1%
remove-double-neg71.1%
Simplified71.1%
add-cbrt-cube71.0%
pow1/371.1%
pow-to-exp71.1%
pow371.1%
log-pow71.1%
log-div71.1%
add-log-exp71.1%
Applied egg-rr71.1%
*-commutative71.1%
associate-*r*71.0%
metadata-eval71.0%
*-un-lft-identity71.0%
exp-diff71.1%
add-exp-log71.1%
clear-num71.2%
Applied egg-rr71.2%
Final simplification62.7%
(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-cbrt-cube3.3%
pow1/33.3%
pow-to-exp3.3%
pow33.3%
log-pow3.3%
log-div3.3%
add-log-exp3.3%
Applied egg-rr3.3%
Taylor expanded in x around inf 62.2%
neg-mul-162.2%
Simplified62.2%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 71.0%
/-rgt-identity71.0%
associate-/r/70.9%
exp-neg71.1%
remove-double-neg71.1%
Simplified71.1%
Final simplification62.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (exp (sqrt (cos x))))))
(if (<= x 1.0)
(/ (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 <= 1.0) {
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 <= 1.0) 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, 1.0], 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 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 < 1Initial 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-cbrt52.3%
log-prod52.3%
pow252.3%
Applied egg-rr52.3%
if 1 < x Initial program 0.0%
/-rgt-identity0.0%
associate-/r/0.0%
exp-neg0.0%
remove-double-neg0.0%
Simplified0.0%
add-cbrt-cube0.0%
pow1/30.0%
pow-to-exp0.0%
pow30.0%
log-pow0.0%
log-div0.0%
add-log-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
Simplified100.0%
(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.3%
/-rgt-identity7.3%
associate-/r/7.3%
exp-neg7.3%
remove-double-neg7.3%
Simplified7.3%
add-cbrt-cube7.3%
pow1/37.3%
pow-to-exp7.3%
pow37.3%
log-pow7.3%
log-div7.3%
add-log-exp7.3%
Applied egg-rr7.3%
Taylor expanded in x around inf 60.1%
neg-mul-160.1%
Simplified60.1%
herbie shell --seed 2024107
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))