
(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 5 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 -2e-311) 1.0 (/ (fmod (+ x 1.0) (sqrt (cos x))) (exp x))))
double code(double x) {
double tmp;
if (x <= -2e-311) {
tmp = 1.0;
} else {
tmp = fmod((x + 1.0), sqrt(cos(x))) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-311)) then
tmp = 1.0d0
else
tmp = mod((x + 1.0d0), sqrt(cos(x))) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-311: tmp = 1.0 else: tmp = math.fmod((x + 1.0), math.sqrt(math.cos(x))) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -2e-311) tmp = 1.0; else tmp = Float64(rem(Float64(x + 1.0), sqrt(cos(x))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -2e-311], 1.0, 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 -2 \cdot 10^{-311}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -1.9999999999999e-311Initial program 7.3%
/-rgt-identity7.3%
associate-/r/7.3%
exp-neg7.3%
remove-double-neg7.3%
Simplified7.3%
add-exp-log7.3%
div-exp7.3%
Applied egg-rr7.3%
Taylor expanded in x around inf 96.3%
neg-mul-196.3%
Simplified96.3%
Taylor expanded in x around 0 100.0%
if -1.9999999999999e-311 < x Initial program 5.6%
/-rgt-identity5.6%
associate-/r/5.6%
exp-neg5.6%
remove-double-neg5.6%
Simplified5.6%
Taylor expanded in x around 0 37.0%
+-commutative37.0%
Simplified37.0%
(FPCore (x) :precision binary64 (if (<= x -2e-311) 1.0 (/ (fmod (+ x 1.0) (+ 1.0 (* (pow x 2.0) -0.25))) (exp x))))
double code(double x) {
double tmp;
if (x <= -2e-311) {
tmp = 1.0;
} else {
tmp = fmod((x + 1.0), (1.0 + (pow(x, 2.0) * -0.25))) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-311)) then
tmp = 1.0d0
else
tmp = mod((x + 1.0d0), (1.0d0 + ((x ** 2.0d0) * (-0.25d0)))) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-311: tmp = 1.0 else: tmp = math.fmod((x + 1.0), (1.0 + (math.pow(x, 2.0) * -0.25))) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -2e-311) tmp = 1.0; else tmp = Float64(rem(Float64(x + 1.0), Float64(1.0 + Float64((x ^ 2.0) * -0.25))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -2e-311], 1.0, N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * -0.25), $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 -2 \cdot 10^{-311}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(1 + {x}^{2} \cdot -0.25\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -1.9999999999999e-311Initial program 7.3%
/-rgt-identity7.3%
associate-/r/7.3%
exp-neg7.3%
remove-double-neg7.3%
Simplified7.3%
add-exp-log7.3%
div-exp7.3%
Applied egg-rr7.3%
Taylor expanded in x around inf 96.3%
neg-mul-196.3%
Simplified96.3%
Taylor expanded in x around 0 100.0%
if -1.9999999999999e-311 < x Initial program 5.6%
/-rgt-identity5.6%
associate-/r/5.6%
exp-neg5.6%
remove-double-neg5.6%
Simplified5.6%
Taylor expanded in x around 0 5.6%
*-commutative5.6%
Simplified5.6%
Taylor expanded in x around 0 37.0%
+-commutative37.0%
Simplified37.0%
(FPCore (x) :precision binary64 (if (<= x -2e-311) 1.0 (fmod (+ x 1.0) 1.0)))
double code(double x) {
double tmp;
if (x <= -2e-311) {
tmp = 1.0;
} else {
tmp = fmod((x + 1.0), 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-311)) then
tmp = 1.0d0
else
tmp = mod((x + 1.0d0), 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-311: tmp = 1.0 else: tmp = math.fmod((x + 1.0), 1.0) return tmp
function code(x) tmp = 0.0 if (x <= -2e-311) tmp = 1.0; else tmp = rem(Float64(x + 1.0), 1.0); end return tmp end
code[x_] := If[LessEqual[x, -2e-311], 1.0, N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-311}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(x + 1\right) \bmod 1\right)\\
\end{array}
\end{array}
if x < -1.9999999999999e-311Initial program 7.3%
/-rgt-identity7.3%
associate-/r/7.3%
exp-neg7.3%
remove-double-neg7.3%
Simplified7.3%
add-exp-log7.3%
div-exp7.3%
Applied egg-rr7.3%
Taylor expanded in x around inf 96.3%
neg-mul-196.3%
Simplified96.3%
Taylor expanded in x around 0 100.0%
if -1.9999999999999e-311 < x Initial program 5.6%
/-rgt-identity5.6%
associate-/r/5.6%
exp-neg5.6%
remove-double-neg5.6%
Simplified5.6%
Taylor expanded in x around 0 5.0%
Taylor expanded in x around 0 5.0%
Taylor expanded in x around 0 5.0%
Taylor expanded in x around 0 36.3%
+-commutative37.0%
Simplified36.3%
(FPCore (x) :precision binary64 (if (<= x -4e-14) 1.0 (exp (- x))))
double code(double x) {
double tmp;
if (x <= -4e-14) {
tmp = 1.0;
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4d-14)) then
tmp = 1.0d0
else
tmp = exp(-x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -4e-14) {
tmp = 1.0;
} else {
tmp = Math.exp(-x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -4e-14: tmp = 1.0 else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if (x <= -4e-14) tmp = 1.0; else tmp = exp(Float64(-x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4e-14) tmp = 1.0; else tmp = exp(-x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4e-14], 1.0, N[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-14}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -4e-14Initial program 71.2%
/-rgt-identity71.2%
associate-/r/71.0%
exp-neg71.4%
remove-double-neg71.4%
Simplified71.4%
add-exp-log71.4%
div-exp72.3%
Applied egg-rr72.3%
Taylor expanded in x around inf 38.4%
neg-mul-138.4%
Simplified38.4%
Taylor expanded in x around 0 100.0%
if -4e-14 < x Initial program 4.5%
/-rgt-identity4.5%
associate-/r/4.5%
exp-neg4.5%
remove-double-neg4.5%
Simplified4.5%
add-exp-log4.5%
div-exp4.5%
Applied egg-rr4.5%
Taylor expanded in x around inf 63.5%
neg-mul-163.5%
Simplified63.5%
(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 6.4%
/-rgt-identity6.4%
associate-/r/6.4%
exp-neg6.4%
remove-double-neg6.4%
Simplified6.4%
add-exp-log6.4%
div-exp6.4%
Applied egg-rr6.4%
Taylor expanded in x around inf 62.8%
neg-mul-162.8%
Simplified62.8%
Taylor expanded in x around 0 47.5%
herbie shell --seed 2024112
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))