
(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
(let* ((t_0 (cbrt (exp (cos x)))) (t_1 (pow (cbrt x) 2.0)))
(if (<= x 500.0)
(/
(fmod
(pow (pow (exp t_1) (cbrt t_1)) (cbrt (cbrt x)))
(sqrt (+ (log (pow t_0 2.0)) (log t_0))))
(exp x))
(exp (- x)))))
double code(double x) {
double t_0 = cbrt(exp(cos(x)));
double t_1 = pow(cbrt(x), 2.0);
double tmp;
if (x <= 500.0) {
tmp = fmod(pow(pow(exp(t_1), cbrt(t_1)), cbrt(cbrt(x))), sqrt((log(pow(t_0, 2.0)) + log(t_0)))) / exp(x);
} else {
tmp = exp(-x);
}
return tmp;
}
function code(x) t_0 = cbrt(exp(cos(x))) t_1 = cbrt(x) ^ 2.0 tmp = 0.0 if (x <= 500.0) tmp = Float64(rem(((exp(t_1) ^ cbrt(t_1)) ^ cbrt(cbrt(x))), sqrt(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[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[x, 500.0], N[(N[With[{TMP1 = N[Power[N[Power[N[Exp[t$95$1], $MachinePrecision], N[Power[t$95$1, 1/3], $MachinePrecision]], $MachinePrecision], N[Power[N[Power[x, 1/3], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision], TMP2 = N[Sqrt[N[(N[Log[N[Power[t$95$0, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$0], $MachinePrecision]), $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^{\cos x}}\\
t_1 := {\left(\sqrt[3]{x}\right)}^{2}\\
\mathbf{if}\;x \leq 500:\\
\;\;\;\;\frac{\left(\left({\left({\left(e^{t\_1}\right)}^{\left(\sqrt[3]{t\_1}\right)}\right)}^{\left(\sqrt[3]{\sqrt[3]{x}}\right)}\right) \bmod \left(\sqrt{\log \left({t\_0}^{2}\right) + \log t\_0}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < 500Initial program 9.8%
/-rgt-identity9.8%
associate-/r/9.8%
exp-neg9.8%
remove-double-neg9.8%
Simplified9.8%
add-log-exp9.8%
add-cube-cbrt58.5%
log-prod58.5%
pow258.5%
Applied egg-rr58.5%
add-cube-cbrt58.5%
exp-prod58.5%
add-cube-cbrt58.5%
cbrt-prod58.5%
pow-unpow58.5%
pow258.5%
pow258.5%
Applied egg-rr58.5%
if 500 < x Initial program 0.0%
exp-neg0.0%
div-inv0.0%
clear-num0.0%
inv-pow0.0%
pow-to-exp0.0%
diff-log0.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
(let* ((t_0 (cbrt (exp (cos x)))))
(if (<= x 350.0)
(/ (fmod (exp x) (sqrt (+ (log (pow t_0 2.0)) (log t_0)))) (exp x))
(exp (* (pow (cbrt x) 2.0) (- (cbrt x)))))))
double code(double x) {
double t_0 = cbrt(exp(cos(x)));
double tmp;
if (x <= 350.0) {
tmp = fmod(exp(x), sqrt((log(pow(t_0, 2.0)) + log(t_0)))) / exp(x);
} else {
tmp = exp((pow(cbrt(x), 2.0) * -cbrt(x)));
}
return tmp;
}
function code(x) t_0 = cbrt(exp(cos(x))) tmp = 0.0 if (x <= 350.0) tmp = Float64(rem(exp(x), sqrt(Float64(log((t_0 ^ 2.0)) + log(t_0)))) / exp(x)); else tmp = exp(Float64((cbrt(x) ^ 2.0) * Float64(-cbrt(x)))); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[Exp[N[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[x, 350.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[(N[Log[N[Power[t$95$0, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision] * (-N[Power[x, 1/3], $MachinePrecision])), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{e^{\cos x}}\\
\mathbf{if}\;x \leq 350:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\log \left({t\_0}^{2}\right) + \log t\_0}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;e^{{\left(\sqrt[3]{x}\right)}^{2} \cdot \left(-\sqrt[3]{x}\right)}\\
\end{array}
\end{array}
if x < 350Initial program 9.7%
/-rgt-identity9.7%
associate-/r/9.7%
exp-neg9.7%
remove-double-neg9.7%
Simplified9.7%
add-log-exp9.7%
add-cube-cbrt58.7%
log-prod58.7%
pow258.7%
Applied egg-rr58.7%
if 350 < x Initial program 0.5%
exp-neg0.5%
div-inv0.5%
clear-num0.5%
inv-pow0.5%
pow-to-exp0.5%
diff-log0.5%
add-log-exp0.5%
Applied egg-rr0.5%
Taylor expanded in x around inf 98.2%
neg-mul-198.2%
Simplified98.2%
add-cube-cbrt98.2%
distribute-rgt-neg-in98.2%
pow298.2%
Applied egg-rr98.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))))
(if (<= (* (exp (- x)) (fmod (exp x) t_0)) 1e-156)
(exp (* (pow (cbrt x) 2.0) (- (cbrt x))))
(exp (- (log (fmod (+ x 1.0) t_0)) x)))))
double code(double x) {
double t_0 = sqrt(cos(x));
double tmp;
if ((exp(-x) * fmod(exp(x), t_0)) <= 1e-156) {
tmp = exp((pow(cbrt(x), 2.0) * -cbrt(x)));
} else {
tmp = exp((log(fmod((x + 1.0), t_0)) - x));
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) tmp = 0.0 if (Float64(exp(Float64(-x)) * rem(exp(x), t_0)) <= 1e-156) tmp = exp(Float64((cbrt(x) ^ 2.0) * Float64(-cbrt(x)))); else tmp = exp(Float64(log(rem(Float64(x + 1.0), t_0)) - x)); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[Exp[(-x)], $MachinePrecision] * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], 1e-156], N[Exp[N[(N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision] * (-N[Power[x, 1/3], $MachinePrecision])), $MachinePrecision]], $MachinePrecision], N[Exp[N[(N[Log[N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
\mathbf{if}\;e^{-x} \cdot \left(\left(e^{x}\right) \bmod t\_0\right) \leq 10^{-156}:\\
\;\;\;\;e^{{\left(\sqrt[3]{x}\right)}^{2} \cdot \left(-\sqrt[3]{x}\right)}\\
\mathbf{else}:\\
\;\;\;\;e^{\log \left(\left(x + 1\right) \bmod t\_0\right) - x}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 1.00000000000000004e-156Initial program 4.2%
exp-neg4.2%
div-inv4.2%
clear-num4.2%
inv-pow4.2%
pow-to-exp4.2%
diff-log4.2%
add-log-exp4.2%
Applied egg-rr4.2%
Taylor expanded in x around inf 57.3%
neg-mul-157.3%
Simplified57.3%
add-cube-cbrt57.3%
distribute-rgt-neg-in57.3%
pow257.3%
Applied egg-rr57.3%
if 1.00000000000000004e-156 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 20.7%
exp-neg20.7%
div-inv20.7%
clear-num20.7%
inv-pow20.7%
pow-to-exp20.7%
diff-log20.7%
add-log-exp20.7%
Applied egg-rr20.7%
Taylor expanded in x around 0 90.2%
+-commutative90.2%
Simplified90.2%
Final simplification65.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))))
(if (<= (* (exp (- x)) (fmod (exp x) t_0)) 1e-156)
(exp (* (pow (cbrt x) 2.0) (- (cbrt x))))
(/ (fmod (+ x 1.0) t_0) (exp x)))))
double code(double x) {
double t_0 = sqrt(cos(x));
double tmp;
if ((exp(-x) * fmod(exp(x), t_0)) <= 1e-156) {
tmp = exp((pow(cbrt(x), 2.0) * -cbrt(x)));
} else {
tmp = fmod((x + 1.0), t_0) / exp(x);
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) tmp = 0.0 if (Float64(exp(Float64(-x)) * rem(exp(x), t_0)) <= 1e-156) tmp = exp(Float64((cbrt(x) ^ 2.0) * Float64(-cbrt(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[N[(N[Exp[(-x)], $MachinePrecision] * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], 1e-156], N[Exp[N[(N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision] * (-N[Power[x, 1/3], $MachinePrecision])), $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}\;e^{-x} \cdot \left(\left(e^{x}\right) \bmod t\_0\right) \leq 10^{-156}:\\
\;\;\;\;e^{{\left(\sqrt[3]{x}\right)}^{2} \cdot \left(-\sqrt[3]{x}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod t\_0\right)}{e^{x}}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 1.00000000000000004e-156Initial program 4.2%
exp-neg4.2%
div-inv4.2%
clear-num4.2%
inv-pow4.2%
pow-to-exp4.2%
diff-log4.2%
add-log-exp4.2%
Applied egg-rr4.2%
Taylor expanded in x around inf 57.3%
neg-mul-157.3%
Simplified57.3%
add-cube-cbrt57.3%
distribute-rgt-neg-in57.3%
pow257.3%
Applied egg-rr57.3%
if 1.00000000000000004e-156 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 20.7%
/-rgt-identity20.7%
associate-/r/20.6%
exp-neg20.7%
remove-double-neg20.7%
Simplified20.7%
Taylor expanded in x around 0 90.2%
+-commutative90.2%
Simplified90.2%
Final simplification65.2%
(FPCore (x) :precision binary64 (exp (* (pow (cbrt x) 2.0) (- (cbrt x)))))
double code(double x) {
return exp((pow(cbrt(x), 2.0) * -cbrt(x)));
}
public static double code(double x) {
return Math.exp((Math.pow(Math.cbrt(x), 2.0) * -Math.cbrt(x)));
}
function code(x) return exp(Float64((cbrt(x) ^ 2.0) * Float64(-cbrt(x)))) end
code[x_] := N[Exp[N[(N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision] * (-N[Power[x, 1/3], $MachinePrecision])), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{{\left(\sqrt[3]{x}\right)}^{2} \cdot \left(-\sqrt[3]{x}\right)}
\end{array}
Initial program 8.1%
exp-neg8.1%
div-inv8.1%
clear-num8.1%
inv-pow8.1%
pow-to-exp8.1%
diff-log8.1%
add-log-exp8.1%
Applied egg-rr8.1%
Taylor expanded in x around inf 63.1%
neg-mul-163.1%
Simplified63.1%
add-cube-cbrt63.1%
distribute-rgt-neg-in63.1%
pow263.1%
Applied egg-rr63.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 8.1%
exp-neg8.1%
div-inv8.1%
clear-num8.1%
inv-pow8.1%
pow-to-exp8.1%
diff-log8.1%
add-log-exp8.1%
Applied egg-rr8.1%
Taylor expanded in x around inf 63.1%
neg-mul-163.1%
Simplified63.1%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 8.1%
exp-neg8.1%
div-inv8.1%
clear-num8.1%
inv-pow8.1%
pow-to-exp8.1%
diff-log8.1%
add-log-exp8.1%
Applied egg-rr8.1%
Taylor expanded in x around inf 63.1%
neg-mul-163.1%
Simplified63.1%
Taylor expanded in x around 0 47.0%
herbie shell --seed 2024185
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))