
(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 -4e-310) 1.0 (/ (fmod x (sqrt (cos x))) (exp x))))
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = 1.0;
} else {
tmp = fmod(x, sqrt(cos(x))) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4d-310)) then
tmp = 1.0d0
else
tmp = mod(x, sqrt(cos(x))) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -4e-310: tmp = 1.0 else: tmp = math.fmod(x, math.sqrt(math.cos(x))) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = 1.0; else tmp = Float64(rem(x, sqrt(cos(x))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -4e-310], 1.0, N[(N[With[{TMP1 = x, 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 -4 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -3.999999999999988e-310Initial program 9.5%
/-rgt-identity9.5%
associate-/r/9.5%
exp-neg9.6%
remove-double-neg9.6%
Simplified9.6%
add-exp-log9.6%
div-exp9.6%
Applied egg-rr9.6%
Taylor expanded in x around inf 97.2%
neg-mul-197.2%
Simplified97.2%
Taylor expanded in x around 0 100.0%
if -3.999999999999988e-310 < x Initial program 5.5%
/-rgt-identity5.5%
associate-/r/5.5%
exp-neg5.5%
remove-double-neg5.5%
Simplified5.5%
Taylor expanded in x around 0 35.1%
+-commutative35.1%
Simplified35.1%
Taylor expanded in x around inf 98.8%
(FPCore (x) :precision binary64 (if (<= x -4e-310) 1.0 (/ (fmod x 1.0) (+ x 1.0))))
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = 1.0;
} else {
tmp = fmod(x, 1.0) / (x + 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4d-310)) then
tmp = 1.0d0
else
tmp = mod(x, 1.0d0) / (x + 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -4e-310: tmp = 1.0 else: tmp = math.fmod(x, 1.0) / (x + 1.0) return tmp
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = 1.0; else tmp = Float64(rem(x, 1.0) / Float64(x + 1.0)); end return tmp end
code[x_] := If[LessEqual[x, -4e-310], 1.0, N[(N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod 1\right)}{x + 1}\\
\end{array}
\end{array}
if x < -3.999999999999988e-310Initial program 9.5%
/-rgt-identity9.5%
associate-/r/9.5%
exp-neg9.6%
remove-double-neg9.6%
Simplified9.6%
add-exp-log9.6%
div-exp9.6%
Applied egg-rr9.6%
Taylor expanded in x around inf 97.2%
neg-mul-197.2%
Simplified97.2%
Taylor expanded in x around 0 100.0%
if -3.999999999999988e-310 < x Initial program 5.5%
/-rgt-identity5.5%
associate-/r/5.5%
exp-neg5.5%
remove-double-neg5.5%
Simplified5.5%
Taylor expanded in x around 0 35.1%
+-commutative35.1%
Simplified35.1%
Taylor expanded in x around 0 6.2%
+-commutative35.1%
Simplified6.2%
Taylor expanded in x around inf 69.9%
Taylor expanded in x around 0 96.8%
Final simplification98.1%
(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 7.1%
/-rgt-identity7.1%
associate-/r/7.1%
exp-neg7.2%
remove-double-neg7.2%
Simplified7.2%
add-exp-log7.2%
div-exp7.2%
Applied egg-rr7.2%
Taylor expanded in x around inf 60.0%
neg-mul-160.0%
Simplified60.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 7.1%
/-rgt-identity7.1%
associate-/r/7.1%
exp-neg7.2%
remove-double-neg7.2%
Simplified7.2%
add-exp-log7.2%
div-exp7.2%
Applied egg-rr7.2%
Taylor expanded in x around inf 60.0%
neg-mul-160.0%
Simplified60.0%
Taylor expanded in x around 0 43.8%
herbie shell --seed 2024116
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))