
(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 (if (<= x -1e-310) 1.0 (if (<= x 0.05) (fmod x 1.0) (/ (fmod (+ x 1.0) 1.0) (exp x)))))
double code(double x) {
double tmp;
if (x <= -1e-310) {
tmp = 1.0;
} else if (x <= 0.05) {
tmp = fmod(x, 1.0);
} else {
tmp = fmod((x + 1.0), 1.0) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1d-310)) then
tmp = 1.0d0
else if (x <= 0.05d0) then
tmp = mod(x, 1.0d0)
else
tmp = mod((x + 1.0d0), 1.0d0) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -1e-310: tmp = 1.0 elif x <= 0.05: tmp = math.fmod(x, 1.0) else: tmp = math.fmod((x + 1.0), 1.0) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -1e-310) tmp = 1.0; elseif (x <= 0.05) tmp = rem(x, 1.0); else tmp = Float64(rem(Float64(x + 1.0), 1.0) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -1e-310], 1.0, If[LessEqual[x, 0.05], N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = 1.0}, 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}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 0.05:\\
\;\;\;\;\left(x \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod 1\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -9.999999999999969e-311Initial program 6.6%
/-rgt-identity6.6%
associate-/r/6.6%
exp-neg6.6%
remove-double-neg6.6%
Simplified6.6%
add-exp-log6.6%
div-exp6.6%
Applied egg-rr6.6%
Taylor expanded in x around inf 97.2%
neg-mul-197.2%
Simplified97.2%
Taylor expanded in x around 0 100.0%
if -9.999999999999969e-311 < x < 0.050000000000000003Initial program 7.2%
/-rgt-identity7.2%
associate-/r/7.2%
exp-neg7.2%
remove-double-neg7.2%
Simplified7.2%
Taylor expanded in x around 0 6.6%
Taylor expanded in x around 0 6.5%
Taylor expanded in x around 0 6.6%
+-commutative6.6%
Simplified6.6%
Taylor expanded in x around inf 98.9%
if 0.050000000000000003 < x Initial program 0.4%
/-rgt-identity0.4%
associate-/r/0.4%
exp-neg0.4%
remove-double-neg0.4%
Simplified0.4%
Taylor expanded in x around 0 0.3%
Taylor expanded in x around 0 98.3%
+-commutative89.2%
Simplified98.3%
(FPCore (x) :precision binary64 (if (<= x -1e-310) 1.0 (if (<= x 0.05) (fmod x 1.0) (exp (- x)))))
double code(double x) {
double tmp;
if (x <= -1e-310) {
tmp = 1.0;
} else if (x <= 0.05) {
tmp = fmod(x, 1.0);
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1d-310)) then
tmp = 1.0d0
else if (x <= 0.05d0) then
tmp = mod(x, 1.0d0)
else
tmp = exp(-x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -1e-310: tmp = 1.0 elif x <= 0.05: tmp = math.fmod(x, 1.0) else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if (x <= -1e-310) tmp = 1.0; elseif (x <= 0.05) tmp = rem(x, 1.0); else tmp = exp(Float64(-x)); end return tmp end
code[x_] := If[LessEqual[x, -1e-310], 1.0, If[LessEqual[x, 0.05], N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[Exp[(-x)], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 0.05:\\
\;\;\;\;\left(x \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -9.999999999999969e-311Initial program 6.6%
/-rgt-identity6.6%
associate-/r/6.6%
exp-neg6.6%
remove-double-neg6.6%
Simplified6.6%
add-exp-log6.6%
div-exp6.6%
Applied egg-rr6.6%
Taylor expanded in x around inf 97.2%
neg-mul-197.2%
Simplified97.2%
Taylor expanded in x around 0 100.0%
if -9.999999999999969e-311 < x < 0.050000000000000003Initial program 7.2%
/-rgt-identity7.2%
associate-/r/7.2%
exp-neg7.2%
remove-double-neg7.2%
Simplified7.2%
Taylor expanded in x around 0 6.6%
Taylor expanded in x around 0 6.5%
Taylor expanded in x around 0 6.6%
+-commutative6.6%
Simplified6.6%
Taylor expanded in x around inf 98.9%
if 0.050000000000000003 < x Initial program 0.4%
/-rgt-identity0.4%
associate-/r/0.4%
exp-neg0.4%
remove-double-neg0.4%
Simplified0.4%
add-exp-log0.4%
div-exp0.4%
Applied egg-rr0.4%
Taylor expanded in x around inf 98.2%
neg-mul-198.2%
Simplified98.2%
(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 5.8%
/-rgt-identity5.8%
associate-/r/5.7%
exp-neg5.8%
remove-double-neg5.8%
Simplified5.8%
add-exp-log5.8%
div-exp5.8%
Applied egg-rr5.8%
Taylor expanded in x around inf 61.0%
neg-mul-161.0%
Simplified61.0%
(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 5.8%
/-rgt-identity5.8%
associate-/r/5.7%
exp-neg5.8%
remove-double-neg5.8%
Simplified5.8%
add-exp-log5.8%
div-exp5.8%
Applied egg-rr5.8%
Taylor expanded in x around inf 61.0%
neg-mul-161.0%
Simplified61.0%
Taylor expanded in x around 0 45.5%
herbie shell --seed 2024117
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))