
(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 6 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
(if (<= x -1e-310)
(/
(fmod
(+ 1.0 (* x (+ 1.0 (* x 0.5))))
(sqrt (+ (log (pow (cbrt E) 2.0)) (log (cbrt E)))))
(exp x))
(/ (fmod (+ x 1.0) (sqrt (cos x))) (exp x))))
double code(double x) {
double tmp;
if (x <= -1e-310) {
tmp = fmod((1.0 + (x * (1.0 + (x * 0.5)))), sqrt((log(pow(cbrt(((double) M_E)), 2.0)) + log(cbrt(((double) M_E)))))) / exp(x);
} else {
tmp = fmod((x + 1.0), sqrt(cos(x))) / exp(x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1e-310) tmp = Float64(rem(Float64(1.0 + Float64(x * Float64(1.0 + Float64(x * 0.5)))), sqrt(Float64(log((cbrt(exp(1)) ^ 2.0)) + log(cbrt(exp(1)))))) / exp(x)); else tmp = Float64(rem(Float64(x + 1.0), sqrt(cos(x))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -1e-310], N[(N[With[{TMP1 = N[(1.0 + N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = N[Sqrt[N[(N[Log[N[Power[N[Power[E, 1/3], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[N[Power[E, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = N[(x + 1.0), $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}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{\left(\left(1 + x \cdot \left(1 + x \cdot 0.5\right)\right) \bmod \left(\sqrt{\log \left({\left(\sqrt[3]{e}\right)}^{2}\right) + \log \left(\sqrt[3]{e}\right)}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -9.999999999999969e-311Initial program 5.7%
/-rgt-identity5.7%
associate-/r/5.7%
exp-neg5.7%
remove-double-neg5.7%
Simplified5.7%
add-log-exp5.7%
add-cube-cbrt98.2%
log-prod98.2%
pow298.2%
Applied egg-rr98.2%
Taylor expanded in x around 0 98.2%
exp-1-e98.2%
Simplified98.2%
Taylor expanded in x around 0 98.2%
*-commutative98.2%
Simplified98.2%
Taylor expanded in x around 0 98.2%
exp-1-e98.2%
Simplified98.2%
if -9.999999999999969e-311 < x Initial program 4.1%
/-rgt-identity4.1%
associate-/r/4.1%
exp-neg4.1%
remove-double-neg4.1%
Simplified4.1%
Taylor expanded in x around 0 38.8%
+-commutative38.8%
Simplified38.8%
(FPCore (x)
:precision binary64
(if (<= x 200.0)
(/
(fmod
(+ 1.0 (* x (+ 1.0 (* x 0.5))))
(sqrt
(fma
(sqrt 0.3333333333333333)
(sqrt 0.3333333333333333)
(* (cos x) 0.6666666666666666))))
(exp x))
(fmod (exp (pow (cbrt (- x)) 3.0)) (sqrt (cos x)))))
double code(double x) {
double tmp;
if (x <= 200.0) {
tmp = fmod((1.0 + (x * (1.0 + (x * 0.5)))), sqrt(fma(sqrt(0.3333333333333333), sqrt(0.3333333333333333), (cos(x) * 0.6666666666666666)))) / exp(x);
} else {
tmp = fmod(exp(pow(cbrt(-x), 3.0)), sqrt(cos(x)));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 200.0) tmp = Float64(rem(Float64(1.0 + Float64(x * Float64(1.0 + Float64(x * 0.5)))), sqrt(fma(sqrt(0.3333333333333333), sqrt(0.3333333333333333), Float64(cos(x) * 0.6666666666666666)))) / exp(x)); else tmp = rem(exp((cbrt(Float64(-x)) ^ 3.0)), sqrt(cos(x))); end return tmp end
code[x_] := If[LessEqual[x, 200.0], N[(N[With[{TMP1 = N[(1.0 + N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = N[Sqrt[N[(N[Sqrt[0.3333333333333333], $MachinePrecision] * N[Sqrt[0.3333333333333333], $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * 0.6666666666666666), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[With[{TMP1 = N[Exp[N[Power[N[Power[(-x), 1/3], $MachinePrecision], 3.0], $MachinePrecision]], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 200:\\
\;\;\;\;\frac{\left(\left(1 + x \cdot \left(1 + x \cdot 0.5\right)\right) \bmod \left(\sqrt{\mathsf{fma}\left(\sqrt{0.3333333333333333}, \sqrt{0.3333333333333333}, \cos x \cdot 0.6666666666666666\right)}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(e^{{\left(\sqrt[3]{-x}\right)}^{3}}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\end{array}
\end{array}
if x < 200Initial program 5.9%
/-rgt-identity5.9%
associate-/r/5.9%
exp-neg6.0%
remove-double-neg6.0%
Simplified6.0%
add-log-exp6.0%
add-cube-cbrt55.2%
log-prod55.2%
pow255.2%
Applied egg-rr55.2%
Taylor expanded in x around 0 55.2%
exp-1-e55.2%
Simplified55.2%
Taylor expanded in x around 0 55.2%
*-commutative55.2%
Simplified55.2%
+-commutative55.2%
add-sqr-sqrt55.2%
fma-define55.2%
pow1/355.2%
log-pow55.2%
log-E55.2%
metadata-eval55.2%
pow1/355.2%
log-pow55.2%
log-E55.2%
metadata-eval55.2%
pow1/39.5%
pow-pow9.5%
metadata-eval9.5%
exp-prod9.5%
*-commutative9.5%
add-log-exp9.5%
*-commutative9.5%
Applied egg-rr9.5%
if 200 < x Initial program 0.3%
Taylor expanded in x around 0 0.1%
add-sqr-sqrt0.1%
sqrt-unprod0.1%
sqr-neg0.1%
sqrt-unprod0.0%
add-sqr-sqrt98.6%
neg-mul-198.6%
exp-prod98.6%
add-log-exp98.6%
add-sqr-sqrt98.6%
log-prod98.6%
unpow-prod-up98.6%
pow1/298.6%
log-pow98.6%
add-log-exp98.6%
pow1/298.6%
log-pow98.6%
add-log-exp98.6%
Applied egg-rr98.6%
pow-sqr98.6%
associate-*r*98.6%
metadata-eval98.6%
*-lft-identity98.6%
exp-prod98.6%
neg-mul-198.6%
Simplified98.6%
add-cube-cbrt98.6%
pow398.6%
Applied egg-rr98.6%
(FPCore (x) :precision binary64 (/ (fmod (+ x 1.0) (sqrt (cos x))) (exp x)))
double code(double x) {
return fmod((x + 1.0), sqrt(cos(x))) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod((x + 1.0d0), sqrt(cos(x))) / exp(x)
end function
def code(x): return math.fmod((x + 1.0), math.sqrt(math.cos(x))) / math.exp(x)
function code(x) return Float64(rem(Float64(x + 1.0), sqrt(cos(x))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[(x + 1.0), $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}
\\
\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}
\end{array}
Initial program 4.8%
/-rgt-identity4.8%
associate-/r/4.8%
exp-neg4.8%
remove-double-neg4.8%
Simplified4.8%
Taylor expanded in x around 0 24.6%
+-commutative24.6%
Simplified24.6%
(FPCore (x) :precision binary64 (if (<= x -1.56e-162) (fmod 1.0 (* (pow x 2.0) (- (/ 1.0 (pow x 2.0)) 0.25))) (fmod (exp (- x)) (+ 1.0 (* (pow x 2.0) -0.25)))))
double code(double x) {
double tmp;
if (x <= -1.56e-162) {
tmp = fmod(1.0, (pow(x, 2.0) * ((1.0 / pow(x, 2.0)) - 0.25)));
} else {
tmp = fmod(exp(-x), (1.0 + (pow(x, 2.0) * -0.25)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.56d-162)) then
tmp = mod(1.0d0, ((x ** 2.0d0) * ((1.0d0 / (x ** 2.0d0)) - 0.25d0)))
else
tmp = mod(exp(-x), (1.0d0 + ((x ** 2.0d0) * (-0.25d0))))
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -1.56e-162: tmp = math.fmod(1.0, (math.pow(x, 2.0) * ((1.0 / math.pow(x, 2.0)) - 0.25))) else: tmp = math.fmod(math.exp(-x), (1.0 + (math.pow(x, 2.0) * -0.25))) return tmp
function code(x) tmp = 0.0 if (x <= -1.56e-162) tmp = rem(1.0, Float64((x ^ 2.0) * Float64(Float64(1.0 / (x ^ 2.0)) - 0.25))); else tmp = rem(exp(Float64(-x)), Float64(1.0 + Float64((x ^ 2.0) * -0.25))); end return tmp end
code[x_] := If[LessEqual[x, -1.56e-162], N[With[{TMP1 = 1.0, TMP2 = N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.25), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[With[{TMP1 = N[Exp[(-x)], $MachinePrecision], TMP2 = N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.56 \cdot 10^{-162}:\\
\;\;\;\;\left(1 \bmod \left({x}^{2} \cdot \left(\frac{1}{{x}^{2}} - 0.25\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(e^{-x}\right) \bmod \left(1 + {x}^{2} \cdot -0.25\right)\right)\\
\end{array}
\end{array}
if x < -1.5600000000000001e-162Initial program 8.4%
Taylor expanded in x around 0 5.9%
Taylor expanded in x around 0 4.0%
Taylor expanded in x around 0 7.0%
Taylor expanded in x around inf 11.4%
if -1.5600000000000001e-162 < x Initial program 3.9%
Taylor expanded in x around 0 3.7%
add-sqr-sqrt2.9%
sqrt-unprod3.7%
sqr-neg3.7%
sqrt-unprod0.9%
add-sqr-sqrt28.9%
neg-mul-128.9%
exp-prod28.9%
add-log-exp28.9%
add-sqr-sqrt28.9%
log-prod28.9%
unpow-prod-up28.9%
pow1/228.9%
log-pow28.9%
add-log-exp28.9%
pow1/228.9%
log-pow28.9%
add-log-exp28.9%
Applied egg-rr28.9%
pow-sqr28.9%
associate-*r*28.9%
metadata-eval28.9%
*-lft-identity28.9%
exp-prod28.9%
neg-mul-128.9%
Simplified28.9%
Taylor expanded in x around 0 28.9%
Final simplification25.2%
(FPCore (x) :precision binary64 (fmod (exp (- x)) (+ 1.0 (* (pow x 2.0) -0.25))))
double code(double x) {
return fmod(exp(-x), (1.0 + (pow(x, 2.0) * -0.25)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(-x), (1.0d0 + ((x ** 2.0d0) * (-0.25d0))))
end function
def code(x): return math.fmod(math.exp(-x), (1.0 + (math.pow(x, 2.0) * -0.25)))
function code(x) return rem(exp(Float64(-x)), Float64(1.0 + Float64((x ^ 2.0) * -0.25))) end
code[x_] := N[With[{TMP1 = N[Exp[(-x)], $MachinePrecision], TMP2 = N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{-x}\right) \bmod \left(1 + {x}^{2} \cdot -0.25\right)\right)
\end{array}
Initial program 4.8%
Taylor expanded in x around 0 4.2%
add-sqr-sqrt2.3%
sqrt-unprod3.7%
sqr-neg3.7%
sqrt-unprod1.4%
add-sqr-sqrt23.5%
neg-mul-123.5%
exp-prod23.5%
add-log-exp23.5%
add-sqr-sqrt23.5%
log-prod23.5%
unpow-prod-up23.5%
pow1/223.5%
log-pow23.5%
add-log-exp23.5%
pow1/223.5%
log-pow23.5%
add-log-exp23.5%
Applied egg-rr23.5%
pow-sqr23.5%
associate-*r*23.5%
metadata-eval23.5%
*-lft-identity23.5%
exp-prod23.5%
neg-mul-123.5%
Simplified23.5%
Taylor expanded in x around 0 23.5%
Final simplification23.5%
(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 4.8%
Taylor expanded in x around 0 4.2%
Taylor expanded in x around 0 4.2%
Taylor expanded in x around 0 4.8%
Taylor expanded in x around 0 23.3%
herbie shell --seed 2024135
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))