
(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 (if (<= x -2e-310) 1.0 (/ (fmod x (sqrt (cos x))) (exp x))))
double code(double x) {
double tmp;
if (x <= -2e-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 <= (-2d-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 <= -2e-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 <= -2e-310) tmp = 1.0; else tmp = Float64(rem(x, sqrt(cos(x))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -2e-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 -2 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 13.0%
/-rgt-identity13.0%
associate-/r/12.9%
exp-neg13.0%
remove-double-neg13.0%
Simplified13.0%
add-exp-log13.0%
div-exp13.0%
Applied egg-rr13.0%
Taylor expanded in x around inf 94.9%
neg-mul-194.9%
Simplified94.9%
Taylor expanded in x around 0 100.0%
if -1.999999999999994e-310 < 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 34.9%
+-commutative34.9%
Simplified34.9%
Taylor expanded in x around inf 99.5%
(FPCore (x) :precision binary64 (if (<= x -2e-310) 1.0 (* (fmod (+ x 1.0) 1.0) (- 1.0 x))))
double code(double x) {
double tmp;
if (x <= -2e-310) {
tmp = 1.0;
} else {
tmp = fmod((x + 1.0), 1.0) * (1.0 - x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = 1.0d0
else
tmp = mod((x + 1.0d0), 1.0d0) * (1.0d0 - x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-310: tmp = 1.0 else: tmp = math.fmod((x + 1.0), 1.0) * (1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= -2e-310) tmp = 1.0; else tmp = Float64(rem(Float64(x + 1.0), 1.0) * Float64(1.0 - x)); end return tmp end
code[x_] := If[LessEqual[x, -2e-310], 1.0, N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(x + 1\right) \bmod 1\right) \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 13.0%
/-rgt-identity13.0%
associate-/r/12.9%
exp-neg13.0%
remove-double-neg13.0%
Simplified13.0%
add-exp-log13.0%
div-exp13.0%
Applied egg-rr13.0%
Taylor expanded in x around inf 94.9%
neg-mul-194.9%
Simplified94.9%
Taylor expanded in x around 0 100.0%
if -1.999999999999994e-310 < 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 34.9%
+-commutative34.9%
Simplified34.9%
Taylor expanded in x around 0 34.8%
Taylor expanded in x around 0 34.8%
associate-*r*34.8%
+-commutative34.8%
+-commutative34.8%
*-lft-identity34.8%
distribute-rgt-out34.8%
+-commutative34.8%
mul-1-neg34.8%
sub-neg34.8%
Simplified34.8%
(FPCore (x) :precision binary64 (if (<= x 5e-308) 1.0 (/ 1.0 (exp x))))
double code(double x) {
double tmp;
if (x <= 5e-308) {
tmp = 1.0;
} else {
tmp = 1.0 / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5d-308) then
tmp = 1.0d0
else
tmp = 1.0d0 / exp(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5e-308) {
tmp = 1.0;
} else {
tmp = 1.0 / Math.exp(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 5e-308: tmp = 1.0 else: tmp = 1.0 / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= 5e-308) tmp = 1.0; else tmp = Float64(1.0 / exp(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5e-308) tmp = 1.0; else tmp = 1.0 / exp(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5e-308], 1.0, N[(1.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{-308}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{x}}\\
\end{array}
\end{array}
if x < 4.99999999999999955e-308Initial program 13.0%
/-rgt-identity13.0%
associate-/r/13.0%
exp-neg13.0%
remove-double-neg13.0%
Simplified13.0%
add-exp-log13.0%
div-exp13.1%
Applied egg-rr13.1%
Taylor expanded in x around inf 94.0%
neg-mul-194.0%
Simplified94.0%
Taylor expanded in x around 0 99.0%
if 4.99999999999999955e-308 < x Initial program 4.1%
/-rgt-identity4.1%
associate-/r/4.1%
exp-neg4.1%
remove-double-neg4.1%
Simplified4.1%
add-exp-log4.1%
div-exp4.1%
Applied egg-rr4.1%
Taylor expanded in x around inf 34.8%
neg-mul-134.8%
Simplified34.8%
exp-neg34.8%
Applied egg-rr34.8%
(FPCore (x) :precision binary64 (if (<= x -2e-310) 1.0 (fmod x 1.0)))
double code(double x) {
double tmp;
if (x <= -2e-310) {
tmp = 1.0;
} else {
tmp = fmod(x, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = 1.0d0
else
tmp = mod(x, 1.0d0)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-310: tmp = 1.0 else: tmp = math.fmod(x, 1.0) return tmp
function code(x) tmp = 0.0 if (x <= -2e-310) tmp = 1.0; else tmp = rem(x, 1.0); end return tmp end
code[x_] := If[LessEqual[x, -2e-310], 1.0, N[With[{TMP1 = x, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\left(x \bmod 1\right)\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 13.0%
/-rgt-identity13.0%
associate-/r/12.9%
exp-neg13.0%
remove-double-neg13.0%
Simplified13.0%
add-exp-log13.0%
div-exp13.0%
Applied egg-rr13.0%
Taylor expanded in x around inf 94.9%
neg-mul-194.9%
Simplified94.9%
Taylor expanded in x around 0 100.0%
if -1.999999999999994e-310 < 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 34.9%
+-commutative34.9%
Simplified34.9%
Taylor expanded in x around inf 99.5%
Taylor expanded in x around 0 69.4%
Taylor expanded in x around 0 99.4%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= x -5e-16) 1.0 (exp (- x))))
double code(double x) {
double tmp;
if (x <= -5e-16) {
tmp = 1.0;
} else {
tmp = exp(-x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-16)) then
tmp = 1.0d0
else
tmp = exp(-x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -5e-16) {
tmp = 1.0;
} else {
tmp = Math.exp(-x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -5e-16: tmp = 1.0 else: tmp = math.exp(-x) return tmp
function code(x) tmp = 0.0 if (x <= -5e-16) tmp = 1.0; else tmp = exp(Float64(-x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -5e-16) tmp = 1.0; else tmp = exp(-x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -5e-16], 1.0, N[Exp[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-16}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -5.0000000000000004e-16Initial program 90.8%
/-rgt-identity90.8%
associate-/r/90.5%
exp-neg90.9%
remove-double-neg90.9%
Simplified90.9%
add-exp-log90.9%
div-exp91.2%
Applied egg-rr91.2%
Taylor expanded in x around inf 54.4%
neg-mul-154.4%
Simplified54.4%
Taylor expanded in x around 0 100.0%
if -5.0000000000000004e-16 < x Initial program 3.8%
/-rgt-identity3.8%
associate-/r/3.8%
exp-neg3.8%
remove-double-neg3.8%
Simplified3.8%
add-exp-log3.8%
div-exp3.8%
Applied egg-rr3.8%
Taylor expanded in x around inf 57.8%
neg-mul-157.8%
Simplified57.8%
(FPCore (x) :precision binary64 (if (<= x -5e-16) 1.0 (/ 1.0 (+ 1.0 (* x (+ 1.0 (* x (+ 0.5 (* x 0.16666666666666666)))))))))
double code(double x) {
double tmp;
if (x <= -5e-16) {
tmp = 1.0;
} else {
tmp = 1.0 / (1.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-16)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (1.0d0 + (x * (1.0d0 + (x * (0.5d0 + (x * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -5e-16) {
tmp = 1.0;
} else {
tmp = 1.0 / (1.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666))))));
}
return tmp;
}
def code(x): tmp = 0 if x <= -5e-16: tmp = 1.0 else: tmp = 1.0 / (1.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666)))))) return tmp
function code(x) tmp = 0.0 if (x <= -5e-16) tmp = 1.0; else tmp = Float64(1.0 / Float64(1.0 + Float64(x * Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -5e-16) tmp = 1.0; else tmp = 1.0 / (1.0 + (x * (1.0 + (x * (0.5 + (x * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -5e-16], 1.0, N[(1.0 / N[(1.0 + N[(x * N[(1.0 + N[(x * N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-16}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + x \cdot \left(1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if x < -5.0000000000000004e-16Initial program 90.8%
/-rgt-identity90.8%
associate-/r/90.5%
exp-neg90.9%
remove-double-neg90.9%
Simplified90.9%
add-exp-log90.9%
div-exp91.2%
Applied egg-rr91.2%
Taylor expanded in x around inf 54.4%
neg-mul-154.4%
Simplified54.4%
Taylor expanded in x around 0 100.0%
if -5.0000000000000004e-16 < x Initial program 3.8%
/-rgt-identity3.8%
associate-/r/3.8%
exp-neg3.8%
remove-double-neg3.8%
Simplified3.8%
add-exp-log3.8%
div-exp3.8%
Applied egg-rr3.8%
Taylor expanded in x around inf 57.8%
neg-mul-157.8%
Simplified57.8%
exp-neg57.8%
Applied egg-rr57.8%
Taylor expanded in x around 0 52.0%
*-commutative52.0%
Simplified52.0%
(FPCore (x) :precision binary64 (if (<= x 2e-304) 1.0 (/ 1.0 (+ 1.0 (* x (+ 1.0 (* x 0.5)))))))
double code(double x) {
double tmp;
if (x <= 2e-304) {
tmp = 1.0;
} else {
tmp = 1.0 / (1.0 + (x * (1.0 + (x * 0.5))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2d-304) then
tmp = 1.0d0
else
tmp = 1.0d0 / (1.0d0 + (x * (1.0d0 + (x * 0.5d0))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 2e-304) {
tmp = 1.0;
} else {
tmp = 1.0 / (1.0 + (x * (1.0 + (x * 0.5))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 2e-304: tmp = 1.0 else: tmp = 1.0 / (1.0 + (x * (1.0 + (x * 0.5)))) return tmp
function code(x) tmp = 0.0 if (x <= 2e-304) tmp = 1.0; else tmp = Float64(1.0 / Float64(1.0 + Float64(x * Float64(1.0 + Float64(x * 0.5))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 2e-304) tmp = 1.0; else tmp = 1.0 / (1.0 + (x * (1.0 + (x * 0.5)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 2e-304], 1.0, N[(1.0 / N[(1.0 + N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{-304}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + x \cdot \left(1 + x \cdot 0.5\right)}\\
\end{array}
\end{array}
if x < 1.99999999999999994e-304Initial program 13.0%
/-rgt-identity13.0%
associate-/r/13.0%
exp-neg13.0%
remove-double-neg13.0%
Simplified13.0%
add-exp-log13.0%
div-exp13.1%
Applied egg-rr13.1%
Taylor expanded in x around inf 92.2%
neg-mul-192.2%
Simplified92.2%
Taylor expanded in x around 0 97.1%
if 1.99999999999999994e-304 < x Initial program 3.9%
/-rgt-identity3.9%
associate-/r/3.9%
exp-neg3.9%
remove-double-neg3.9%
Simplified3.9%
add-exp-log3.9%
div-exp3.9%
Applied egg-rr3.9%
Taylor expanded in x around inf 35.2%
neg-mul-135.2%
Simplified35.2%
exp-neg35.2%
Applied egg-rr35.2%
Taylor expanded in x around 0 24.6%
*-commutative24.6%
Simplified24.6%
(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.5%
/-rgt-identity7.5%
associate-/r/7.5%
exp-neg7.5%
remove-double-neg7.5%
Simplified7.5%
add-exp-log7.5%
div-exp7.5%
Applied egg-rr7.5%
Taylor expanded in x around inf 57.7%
neg-mul-157.7%
Simplified57.7%
Taylor expanded in x around 0 41.0%
herbie shell --seed 2024110
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))