
(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 (<= (* t_0 (exp (- x))) 2.0) (/ t_0 (exp x)) (fmod 1.0 1.0))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double tmp;
if ((t_0 * exp(-x)) <= 2.0) {
tmp = t_0 / exp(x);
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = mod(exp(x), sqrt(cos(x)))
if ((t_0 * exp(-x)) <= 2.0d0) then
tmp = t_0 / exp(x)
else
tmp = mod(1.0d0, 1.0d0)
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) tmp = 0 if (t_0 * math.exp(-x)) <= 2.0: tmp = t_0 / math.exp(x) else: tmp = math.fmod(1.0, 1.0) return tmp
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) tmp = 0.0 if (Float64(t_0 * exp(Float64(-x))) <= 2.0) tmp = Float64(t_0 / exp(x)); else tmp = rem(1.0, 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[N[(t$95$0 * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 2.0], N[(t$95$0 / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;t_0 \cdot e^{-x} \leq 2:\\
\;\;\;\;\frac{t_0}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 7.5%
/-rgt-identity7.5%
associate-/r/7.5%
exp-neg7.5%
remove-double-neg7.5%
Simplified7.5%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 0.0%
Taylor expanded in x around 0 0.0%
Applied egg-rr100.0%
+-lft-identity100.0%
cos-0100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification25.6%
(FPCore (x) :precision binary64 (if (<= x 1.0) (* (fmod (exp x) (sqrt (cos x))) (- 1.0 x)) (fmod 1.0 1.0)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = fmod(exp(x), sqrt(cos(x))) * (1.0 - x);
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = mod(exp(x), sqrt(cos(x))) * (1.0d0 - x)
else
tmp = mod(1.0d0, 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= 1.0: tmp = math.fmod(math.exp(x), math.sqrt(math.cos(x))) * (1.0 - x) else: tmp = math.fmod(1.0, 1.0) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(rem(exp(x), sqrt(cos(x))) * Float64(1.0 - x)); else tmp = rem(1.0, 1.0); end return tmp end
code[x_] := If[LessEqual[x, 1.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[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if x < 1Initial program 7.4%
Taylor expanded in x around 0 6.8%
associate-*r*6.8%
neg-mul-16.8%
distribute-lft1-in6.8%
Simplified6.8%
Taylor expanded in x around 0 6.8%
+-commutative6.8%
mul-1-neg6.8%
unsub-neg6.8%
*-lft-identity6.8%
distribute-rgt-out--6.8%
Simplified6.8%
if 1 < x Initial program 0.7%
Taylor expanded in x around 0 0.2%
Applied egg-rr96.4%
+-lft-identity96.4%
cos-096.4%
metadata-eval96.4%
Simplified96.4%
Final simplification25.0%
(FPCore (x) :precision binary64 (if (<= x 50.0) (fmod (exp x) (sqrt (cos x))) (fmod 1.0 1.0)))
double code(double x) {
double tmp;
if (x <= 50.0) {
tmp = fmod(exp(x), sqrt(cos(x)));
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 50.0d0) then
tmp = mod(exp(x), sqrt(cos(x)))
else
tmp = mod(1.0d0, 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= 50.0: tmp = math.fmod(math.exp(x), math.sqrt(math.cos(x))) else: tmp = math.fmod(1.0, 1.0) return tmp
function code(x) tmp = 0.0 if (x <= 50.0) tmp = rem(exp(x), sqrt(cos(x))); else tmp = rem(1.0, 1.0); end return tmp end
code[x_] := If[LessEqual[x, 50.0], N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 50:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if x < 50Initial program 7.5%
Taylor expanded in x around 0 6.4%
if 50 < x Initial program 0.4%
Taylor expanded in x around 0 0.1%
Applied egg-rr98.2%
+-lft-identity98.2%
cos-098.2%
metadata-eval98.2%
Simplified98.2%
Final simplification24.7%
(FPCore (x) :precision binary64 (fmod 1.0 1.0))
double code(double x) {
return fmod(1.0, 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(1.0d0, 1.0d0)
end function
def code(x): return math.fmod(1.0, 1.0)
function code(x) return rem(1.0, 1.0) end
code[x_] := N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(1 \bmod 1\right)
\end{array}
Initial program 6.0%
Taylor expanded in x around 0 5.1%
Applied egg-rr22.9%
+-lft-identity22.9%
cos-022.9%
metadata-eval22.9%
Simplified22.9%
Final simplification22.9%
herbie shell --seed 2023332
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))