
(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 4 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)))))
(if (<= x -5e-310)
1.0
(if (<= x 200.0)
(pow
(expm1 (log1p (exp (pow (cbrt (- (log t_0) x)) 2.0))))
(cbrt (- (log (+ (+ 1.0 t_0) -1.0)) x)))
1.0))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double tmp;
if (x <= -5e-310) {
tmp = 1.0;
} else if (x <= 200.0) {
tmp = pow(expm1(log1p(exp(pow(cbrt((log(t_0) - x)), 2.0)))), cbrt((log(((1.0 + t_0) + -1.0)) - x)));
} else {
tmp = 1.0;
}
return tmp;
}
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) tmp = 0.0 if (x <= -5e-310) tmp = 1.0; elseif (x <= 200.0) tmp = expm1(log1p(exp((cbrt(Float64(log(t_0) - x)) ^ 2.0)))) ^ cbrt(Float64(log(Float64(Float64(1.0 + t_0) + -1.0)) - x)); else tmp = 1.0; 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]}, If[LessEqual[x, -5e-310], 1.0, If[LessEqual[x, 200.0], N[Power[N[(Exp[N[Log[1 + N[Exp[N[Power[N[Power[N[(N[Log[t$95$0], $MachinePrecision] - x), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision], N[Power[N[(N[Log[N[(N[(1.0 + t$95$0), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 200:\\
\;\;\;\;{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{{\left(\sqrt[3]{\log t_0 - x}\right)}^{2}}\right)\right)\right)}^{\left(\sqrt[3]{\log \left(\left(1 + t_0\right) + -1\right) - x}\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4.999999999999985e-310 or 200 < x Initial program 8.7%
exp-neg8.7%
associate-*r/8.7%
*-rgt-identity8.7%
Simplified8.7%
add-exp-log8.7%
div-exp8.8%
Applied egg-rr8.8%
add-cube-cbrt8.8%
exp-prod8.8%
pow28.8%
Applied egg-rr8.8%
Taylor expanded in x around inf 70.7%
if -4.999999999999985e-310 < x < 200Initial program 10.2%
exp-neg10.2%
associate-*r/10.2%
*-rgt-identity10.2%
Simplified10.2%
add-exp-log10.2%
div-exp10.2%
Applied egg-rr10.2%
add-cube-cbrt10.1%
exp-prod10.1%
pow210.1%
Applied egg-rr10.1%
expm1-log1p-u10.1%
expm1-udef10.2%
log1p-udef10.2%
add-exp-log10.2%
Applied egg-rr10.2%
expm1-log1p-u10.2%
Applied egg-rr10.2%
Final simplification48.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (fmod (exp x) (sqrt (cos x)))))
(if (<= x -5e-310)
1.0
(if (<= x 200.0)
(pow
(exp (pow (cbrt (- (log t_0) x)) 2.0))
(cbrt (- (log (+ (+ 1.0 t_0) -1.0)) x)))
1.0))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double tmp;
if (x <= -5e-310) {
tmp = 1.0;
} else if (x <= 200.0) {
tmp = pow(exp(pow(cbrt((log(t_0) - x)), 2.0)), cbrt((log(((1.0 + t_0) + -1.0)) - x)));
} else {
tmp = 1.0;
}
return tmp;
}
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) tmp = 0.0 if (x <= -5e-310) tmp = 1.0; elseif (x <= 200.0) tmp = exp((cbrt(Float64(log(t_0) - x)) ^ 2.0)) ^ cbrt(Float64(log(Float64(Float64(1.0 + t_0) + -1.0)) - x)); else tmp = 1.0; 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]}, If[LessEqual[x, -5e-310], 1.0, If[LessEqual[x, 200.0], N[Power[N[Exp[N[Power[N[Power[N[(N[Log[t$95$0], $MachinePrecision] - x), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision], N[Power[N[(N[Log[N[(N[(1.0 + t$95$0), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 200:\\
\;\;\;\;{\left(e^{{\left(\sqrt[3]{\log t_0 - x}\right)}^{2}}\right)}^{\left(\sqrt[3]{\log \left(\left(1 + t_0\right) + -1\right) - x}\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4.999999999999985e-310 or 200 < x Initial program 8.7%
exp-neg8.7%
associate-*r/8.7%
*-rgt-identity8.7%
Simplified8.7%
add-exp-log8.7%
div-exp8.8%
Applied egg-rr8.8%
add-cube-cbrt8.8%
exp-prod8.8%
pow28.8%
Applied egg-rr8.8%
Taylor expanded in x around inf 70.7%
if -4.999999999999985e-310 < x < 200Initial program 10.2%
exp-neg10.2%
associate-*r/10.2%
*-rgt-identity10.2%
Simplified10.2%
add-exp-log10.2%
div-exp10.2%
Applied egg-rr10.2%
add-cube-cbrt10.1%
exp-prod10.1%
pow210.1%
Applied egg-rr10.1%
expm1-log1p-u10.1%
expm1-udef10.2%
log1p-udef10.2%
add-exp-log10.2%
Applied egg-rr10.2%
Final simplification48.5%
(FPCore (x) :precision binary64 (if (<= x -5e-310) 1.0 (if (<= x 200.0) (/ (fmod (exp x) (sqrt (cos x))) (exp x)) 1.0)))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = 1.0;
} else if (x <= 200.0) {
tmp = fmod(exp(x), sqrt(cos(x))) / exp(x);
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-310)) then
tmp = 1.0d0
else if (x <= 200.0d0) then
tmp = mod(exp(x), sqrt(cos(x))) / exp(x)
else
tmp = 1.0d0
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -5e-310: tmp = 1.0 elif x <= 200.0: tmp = math.fmod(math.exp(x), math.sqrt(math.cos(x))) / math.exp(x) else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = 1.0; elseif (x <= 200.0) tmp = Float64(rem(exp(x), sqrt(cos(x))) / exp(x)); else tmp = 1.0; end return tmp end
code[x_] := If[LessEqual[x, -5e-310], 1.0, If[LessEqual[x, 200.0], 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], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 200:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4.999999999999985e-310 or 200 < x Initial program 8.7%
exp-neg8.7%
associate-*r/8.7%
*-rgt-identity8.7%
Simplified8.7%
add-exp-log8.7%
div-exp8.8%
Applied egg-rr8.8%
add-cube-cbrt8.8%
exp-prod8.8%
pow28.8%
Applied egg-rr8.8%
Taylor expanded in x around inf 70.7%
if -4.999999999999985e-310 < x < 200Initial program 10.2%
exp-neg10.2%
associate-*r/10.2%
*-rgt-identity10.2%
Simplified10.2%
Final simplification48.5%
(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 9.2%
exp-neg9.3%
associate-*r/9.3%
*-rgt-identity9.3%
Simplified9.3%
add-exp-log9.3%
div-exp9.3%
Applied egg-rr9.3%
add-cube-cbrt9.3%
exp-prod9.3%
pow29.3%
Applied egg-rr9.3%
Taylor expanded in x around inf 46.7%
Final simplification46.7%
herbie shell --seed 2023279
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))