
(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 3 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 (sqrt (cos x))))))
(if (<= x 0.002)
(/ (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.002) {
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.002) 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.002], 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.002:\\
\;\;\;\;\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 < 2e-3Initial program 7.8%
/-rgt-identity7.8%
associate-/r/7.8%
exp-neg7.8%
remove-double-neg7.8%
Simplified7.8%
add-log-exp7.8%
add-cube-cbrt50.5%
log-prod50.5%
pow250.5%
Applied egg-rr50.5%
if 2e-3 < x Initial program 0.0%
/-rgt-identity0.0%
associate-/r/0.0%
exp-neg0.0%
remove-double-neg0.0%
Simplified0.0%
add-cube-cbrt0.0%
pow30.0%
pow-to-exp0.0%
pow1/30.0%
log-pow0.0%
log-div0.0%
add-log-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (exp (+ (- 1.0 x) -1.0)))
double code(double x) {
return exp(((1.0 - x) + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(((1.0d0 - x) + (-1.0d0)))
end function
public static double code(double x) {
return Math.exp(((1.0 - x) + -1.0));
}
def code(x): return math.exp(((1.0 - x) + -1.0))
function code(x) return exp(Float64(Float64(1.0 - x) + -1.0)) end
function tmp = code(x) tmp = exp(((1.0 - x) + -1.0)); end
code[x_] := N[Exp[N[(N[(1.0 - x), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(1 - x\right) + -1}
\end{array}
Initial program 6.5%
/-rgt-identity6.5%
associate-/r/6.5%
exp-neg6.5%
remove-double-neg6.5%
Simplified6.5%
add-cube-cbrt6.5%
pow36.5%
pow-to-exp6.5%
pow1/36.5%
log-pow6.5%
log-div6.5%
add-log-exp6.5%
Applied egg-rr6.5%
Taylor expanded in x around inf 57.4%
*-commutative57.4%
Simplified57.4%
expm1-log1p-u40.2%
expm1-undefine40.2%
*-commutative40.2%
*-commutative40.2%
associate-*r*40.2%
metadata-eval40.2%
neg-mul-140.2%
log1p-define40.2%
sub-neg40.2%
add-exp-log57.4%
Applied egg-rr57.4%
Final simplification57.4%
(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.5%
/-rgt-identity6.5%
associate-/r/6.5%
exp-neg6.5%
remove-double-neg6.5%
Simplified6.5%
add-cube-cbrt6.5%
pow36.5%
pow-to-exp6.5%
pow1/36.5%
log-pow6.5%
log-div6.5%
add-log-exp6.5%
Applied egg-rr6.5%
Taylor expanded in x around inf 57.4%
*-commutative57.4%
Simplified57.4%
Taylor expanded in x around 0 57.4%
neg-mul-157.4%
Simplified57.4%
herbie shell --seed 2024098
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))