
(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 8 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 (sqrt (cos x))))
(/
(fmod (exp x) (+ (* t_0 0.6666666666666666) (log (cbrt (exp t_0)))))
(exp x))))
double code(double x) {
double t_0 = sqrt(cos(x));
return fmod(exp(x), ((t_0 * 0.6666666666666666) + log(cbrt(exp(t_0))))) / exp(x);
}
function code(x) t_0 = sqrt(cos(x)) return Float64(rem(exp(x), Float64(Float64(t_0 * 0.6666666666666666) + log(cbrt(exp(t_0))))) / exp(x)) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[(t$95$0 * 0.6666666666666666), $MachinePrecision] + N[Log[N[Power[N[Exp[t$95$0], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
\frac{\left(\left(e^{x}\right) \bmod \left(t\_0 \cdot 0.6666666666666666 + \log \left(\sqrt[3]{e^{t\_0}}\right)\right)\right)}{e^{x}}
\end{array}
\end{array}
Initial program 8.3%
/-rgt-identity8.3%
associate-/r/8.3%
exp-neg8.3%
remove-double-neg8.3%
Simplified8.3%
add-log-exp8.3%
add-cube-cbrt42.8%
log-prod42.8%
pow242.8%
Applied egg-rr42.8%
unpow242.8%
log-prod42.8%
pow1/342.8%
log-pow42.8%
add-log-exp42.8%
pow1/342.9%
log-pow42.9%
add-log-exp42.9%
Applied egg-rr42.9%
distribute-rgt-out42.9%
metadata-eval42.9%
Simplified42.9%
Final simplification42.9%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (+ 0.6666666666666666 (log (cbrt E)))) (exp x)))
double code(double x) {
return fmod(exp(x), (0.6666666666666666 + log(cbrt(((double) M_E))))) / exp(x);
}
function code(x) return Float64(rem(exp(x), Float64(0.6666666666666666 + log(cbrt(exp(1))))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(0.6666666666666666 + N[Log[N[Power[E, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(e^{x}\right) \bmod \left(0.6666666666666666 + \log \left(\sqrt[3]{e}\right)\right)\right)}{e^{x}}
\end{array}
Initial program 8.3%
/-rgt-identity8.3%
associate-/r/8.3%
exp-neg8.3%
remove-double-neg8.3%
Simplified8.3%
add-log-exp8.3%
add-cube-cbrt42.8%
log-prod42.8%
pow242.8%
Applied egg-rr42.8%
unpow242.8%
log-prod42.8%
pow1/342.8%
log-pow42.8%
add-log-exp42.8%
pow1/342.9%
log-pow42.9%
add-log-exp42.9%
Applied egg-rr42.9%
distribute-rgt-out42.9%
metadata-eval42.9%
Simplified42.9%
Taylor expanded in x around 0 42.4%
exp-1-e42.4%
Simplified42.4%
Final simplification42.4%
(FPCore (x) :precision binary64 (if (<= x -5.5e-17) (/ (fmod (exp x) 1.0) (exp x)) (fmod (exp x) (+ 0.6666666666666666 (log (cbrt E))))))
double code(double x) {
double tmp;
if (x <= -5.5e-17) {
tmp = fmod(exp(x), 1.0) / exp(x);
} else {
tmp = fmod(exp(x), (0.6666666666666666 + log(cbrt(((double) M_E)))));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -5.5e-17) tmp = Float64(rem(exp(x), 1.0) / exp(x)); else tmp = rem(exp(x), Float64(0.6666666666666666 + log(cbrt(exp(1))))); end return tmp end
code[x_] := If[LessEqual[x, -5.5e-17], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(0.6666666666666666 + N[Log[N[Power[E, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-17}:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod \left(0.6666666666666666 + \log \left(\sqrt[3]{e}\right)\right)\right)\\
\end{array}
\end{array}
if x < -5.50000000000000001e-17Initial program 99.8%
/-rgt-identity99.8%
associate-/r/99.7%
exp-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
if -5.50000000000000001e-17 < x Initial program 5.0%
/-rgt-identity5.0%
associate-/r/5.0%
exp-neg5.0%
remove-double-neg5.0%
Simplified5.0%
add-log-exp5.0%
add-cube-cbrt40.7%
log-prod40.7%
pow240.7%
Applied egg-rr40.7%
unpow240.7%
log-prod40.7%
pow1/340.7%
log-pow40.7%
add-log-exp40.7%
pow1/340.8%
log-pow40.8%
add-log-exp40.8%
Applied egg-rr40.8%
distribute-rgt-out40.8%
metadata-eval40.8%
Simplified40.8%
Taylor expanded in x around 0 40.4%
exp-1-e40.4%
Simplified40.4%
Taylor expanded in x around 0 40.3%
Final simplification42.4%
(FPCore (x) :precision binary64 (* (fmod (exp x) (+ 0.6666666666666666 (log (cbrt E)))) (- 1.0 x)))
double code(double x) {
return fmod(exp(x), (0.6666666666666666 + log(cbrt(((double) M_E))))) * (1.0 - x);
}
function code(x) return Float64(rem(exp(x), Float64(0.6666666666666666 + log(cbrt(exp(1))))) * Float64(1.0 - x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(0.6666666666666666 + N[Log[N[Power[E, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(0.6666666666666666 + \log \left(\sqrt[3]{e}\right)\right)\right) \cdot \left(1 - x\right)
\end{array}
Initial program 8.3%
/-rgt-identity8.3%
associate-/r/8.3%
exp-neg8.3%
remove-double-neg8.3%
Simplified8.3%
add-log-exp8.3%
add-cube-cbrt42.8%
log-prod42.8%
pow242.8%
Applied egg-rr42.8%
unpow242.8%
log-prod42.8%
pow1/342.8%
log-pow42.8%
add-log-exp42.8%
pow1/342.9%
log-pow42.9%
add-log-exp42.9%
Applied egg-rr42.9%
distribute-rgt-out42.9%
metadata-eval42.9%
Simplified42.9%
Taylor expanded in x around 0 42.4%
exp-1-e42.4%
Simplified42.4%
Taylor expanded in x around 0 41.6%
associate-*r*41.6%
neg-mul-141.6%
distribute-lft1-in41.6%
+-commutative41.6%
sub-neg41.6%
Simplified41.6%
Final simplification41.6%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (+ 1.0 (* (* x x) -0.25))) (exp x)))
double code(double x) {
return fmod(exp(x), (1.0 + ((x * x) * -0.25))) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), (1.0d0 + ((x * x) * (-0.25d0)))) / exp(x)
end function
def code(x): return math.fmod(math.exp(x), (1.0 + ((x * x) * -0.25))) / math.exp(x)
function code(x) return Float64(rem(exp(x), Float64(1.0 + Float64(Float64(x * x) * -0.25))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(e^{x}\right) \bmod \left(1 + \left(x \cdot x\right) \cdot -0.25\right)\right)}{e^{x}}
\end{array}
Initial program 8.3%
/-rgt-identity8.3%
associate-/r/8.3%
exp-neg8.3%
remove-double-neg8.3%
Simplified8.3%
Taylor expanded in x around 0 8.2%
*-commutative8.2%
Simplified8.2%
unpow28.2%
Applied egg-rr8.2%
Final simplification8.2%
(FPCore (x) :precision binary64 (/ (fmod (exp x) 1.0) (exp x)))
double code(double x) {
return fmod(exp(x), 1.0) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), 1.0d0) / exp(x)
end function
def code(x): return math.fmod(math.exp(x), 1.0) / math.exp(x)
function code(x) return Float64(rem(exp(x), 1.0) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}
\end{array}
Initial program 8.3%
/-rgt-identity8.3%
associate-/r/8.3%
exp-neg8.3%
remove-double-neg8.3%
Simplified8.3%
Taylor expanded in x around 0 7.8%
Final simplification7.8%
(FPCore (x) :precision binary64 (* (- 1.0 x) (fmod (exp x) 1.0)))
double code(double x) {
return (1.0 - x) * fmod(exp(x), 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - x) * mod(exp(x), 1.0d0)
end function
def code(x): return (1.0 - x) * math.fmod(math.exp(x), 1.0)
function code(x) return Float64(Float64(1.0 - x) * rem(exp(x), 1.0)) end
code[x_] := N[(N[(1.0 - x), $MachinePrecision] * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot \left(\left(e^{x}\right) \bmod 1\right)
\end{array}
Initial program 8.3%
/-rgt-identity8.3%
associate-/r/8.3%
exp-neg8.3%
remove-double-neg8.3%
Simplified8.3%
Taylor expanded in x around 0 7.8%
Taylor expanded in x around 0 7.0%
+-commutative7.0%
*-lft-identity7.0%
associate-*r*7.0%
neg-mul-17.0%
distribute-rgt-out7.0%
sub-neg7.0%
Simplified7.0%
Final simplification7.0%
(FPCore (x) :precision binary64 (fmod (exp x) 1.0))
double code(double x) {
return fmod(exp(x), 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), 1.0d0)
end function
def code(x): return math.fmod(math.exp(x), 1.0)
function code(x) return rem(exp(x), 1.0) end
code[x_] := N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod 1\right)
\end{array}
Initial program 8.3%
/-rgt-identity8.3%
associate-/r/8.3%
exp-neg8.3%
remove-double-neg8.3%
Simplified8.3%
Taylor expanded in x around 0 7.8%
Taylor expanded in x around 0 6.2%
Final simplification6.2%
herbie shell --seed 2024048
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))