
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))))
(if (<= x -2.15e-37)
(fma t_0 (cos x) (* (sin eps) (- (sin x))))
(if (<= x 9e-22)
(* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5))))
(- (* (cos x) (log (exp t_0))) (* (sin eps) (sin x)))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double tmp;
if (x <= -2.15e-37) {
tmp = fma(t_0, cos(x), (sin(eps) * -sin(x)));
} else if (x <= 9e-22) {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = (cos(x) * log(exp(t_0))) - (sin(eps) * sin(x));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) tmp = 0.0 if (x <= -2.15e-37) tmp = fma(t_0, cos(x), Float64(sin(eps) * Float64(-sin(x)))); elseif (x <= 9e-22) tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = Float64(Float64(cos(x) * log(exp(t_0))) - Float64(sin(eps) * sin(x))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.15e-37], N[(t$95$0 * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9e-22], N[(N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Log[N[Exp[t$95$0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
\mathbf{if}\;x \leq -2.15 \cdot 10^{-37}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-22}:\\
\;\;\;\;\sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \log \left(e^{t_0}\right) - \sin \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if x < -2.14999999999999984e-37Initial program 9.7%
sub-neg9.7%
cos-sum40.9%
associate-+l-41.1%
fma-neg41.2%
Applied egg-rr41.2%
Taylor expanded in x around inf 41.1%
associate--r+99.3%
*-commutative99.3%
*-rgt-identity99.3%
distribute-lft-out--99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
*-commutative99.3%
Simplified99.3%
cancel-sign-sub-inv99.3%
*-commutative99.3%
fma-def99.4%
Applied egg-rr99.4%
if -2.14999999999999984e-37 < x < 8.99999999999999973e-22Initial program 76.7%
diff-cos92.9%
div-inv92.9%
associate--l+92.9%
metadata-eval92.9%
div-inv92.9%
+-commutative92.9%
associate-+l+92.9%
metadata-eval92.9%
Applied egg-rr92.9%
associate-*r*92.9%
*-commutative92.9%
*-commutative92.9%
+-commutative92.9%
count-292.9%
fma-def92.9%
sub-neg92.9%
mul-1-neg92.9%
+-commutative92.9%
associate-+r+99.6%
mul-1-neg99.6%
sub-neg99.6%
+-inverses99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
neg-sub099.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
if 8.99999999999999973e-22 < x Initial program 9.3%
sub-neg9.3%
cos-sum53.9%
associate-+l-53.9%
fma-neg54.0%
Applied egg-rr54.0%
Taylor expanded in x around inf 53.9%
associate--r+99.3%
*-commutative99.3%
*-rgt-identity99.3%
distribute-lft-out--99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
*-commutative99.3%
Simplified99.3%
add-log-exp99.3%
Applied egg-rr99.3%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (- (* (cos x) (/ (pow (sin eps) 2.0) (- -1.0 (cos eps)))) (* (sin eps) (sin x))))
double code(double x, double eps) {
return (cos(x) * (pow(sin(eps), 2.0) / (-1.0 - cos(eps)))) - (sin(eps) * sin(x));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (cos(x) * ((sin(eps) ** 2.0d0) / ((-1.0d0) - cos(eps)))) - (sin(eps) * sin(x))
end function
public static double code(double x, double eps) {
return (Math.cos(x) * (Math.pow(Math.sin(eps), 2.0) / (-1.0 - Math.cos(eps)))) - (Math.sin(eps) * Math.sin(x));
}
def code(x, eps): return (math.cos(x) * (math.pow(math.sin(eps), 2.0) / (-1.0 - math.cos(eps)))) - (math.sin(eps) * math.sin(x))
function code(x, eps) return Float64(Float64(cos(x) * Float64((sin(eps) ^ 2.0) / Float64(-1.0 - cos(eps)))) - Float64(sin(eps) * sin(x))) end
function tmp = code(x, eps) tmp = (cos(x) * ((sin(eps) ^ 2.0) / (-1.0 - cos(eps)))) - (sin(eps) * sin(x)); end
code[x_, eps_] := N[(N[(N[Cos[x], $MachinePrecision] * N[(N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision] / N[(-1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{{\sin \varepsilon}^{2}}{-1 - \cos \varepsilon} - \sin \varepsilon \cdot \sin x
\end{array}
Initial program 38.9%
sub-neg38.9%
cos-sum60.0%
associate-+l-60.1%
fma-neg60.1%
Applied egg-rr60.1%
Taylor expanded in x around inf 60.1%
associate--r+92.5%
*-commutative92.5%
*-rgt-identity92.5%
distribute-lft-out--92.5%
sub-neg92.5%
metadata-eval92.5%
+-commutative92.5%
*-commutative92.5%
Simplified92.5%
flip-+92.2%
metadata-eval92.2%
1-sub-cos99.1%
pow299.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))))
(if (<= x -1.76e-37)
(fma t_0 (cos x) (* (sin eps) (- (sin x))))
(if (<= x 1.2e-21)
(* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5))))
(- (* (cos x) t_0) (* (sin eps) (sin x)))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double tmp;
if (x <= -1.76e-37) {
tmp = fma(t_0, cos(x), (sin(eps) * -sin(x)));
} else if (x <= 1.2e-21) {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = (cos(x) * t_0) - (sin(eps) * sin(x));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) tmp = 0.0 if (x <= -1.76e-37) tmp = fma(t_0, cos(x), Float64(sin(eps) * Float64(-sin(x)))); elseif (x <= 1.2e-21) tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = Float64(Float64(cos(x) * t_0) - Float64(sin(eps) * sin(x))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.76e-37], N[(t$95$0 * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.2e-21], N[(N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
\mathbf{if}\;x \leq -1.76 \cdot 10^{-37}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-21}:\\
\;\;\;\;\sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot t_0 - \sin \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if x < -1.76000000000000006e-37Initial program 9.7%
sub-neg9.7%
cos-sum40.9%
associate-+l-41.1%
fma-neg41.2%
Applied egg-rr41.2%
Taylor expanded in x around inf 41.1%
associate--r+99.3%
*-commutative99.3%
*-rgt-identity99.3%
distribute-lft-out--99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
*-commutative99.3%
Simplified99.3%
cancel-sign-sub-inv99.3%
*-commutative99.3%
fma-def99.4%
Applied egg-rr99.4%
if -1.76000000000000006e-37 < x < 1.2e-21Initial program 76.7%
diff-cos92.9%
div-inv92.9%
associate--l+92.9%
metadata-eval92.9%
div-inv92.9%
+-commutative92.9%
associate-+l+92.9%
metadata-eval92.9%
Applied egg-rr92.9%
associate-*r*92.9%
*-commutative92.9%
*-commutative92.9%
+-commutative92.9%
count-292.9%
fma-def92.9%
sub-neg92.9%
mul-1-neg92.9%
+-commutative92.9%
associate-+r+99.6%
mul-1-neg99.6%
sub-neg99.6%
+-inverses99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
neg-sub099.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
if 1.2e-21 < x Initial program 9.3%
sub-neg9.3%
cos-sum53.9%
associate-+l-53.9%
fma-neg54.0%
Applied egg-rr54.0%
Taylor expanded in x around inf 53.9%
associate--r+99.3%
*-commutative99.3%
*-rgt-identity99.3%
distribute-lft-out--99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
*-commutative99.3%
Simplified99.3%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= x -2.85e-39) (not (<= x 8.2e-22))) (- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x))) (* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((x <= -2.85e-39) || !(x <= 8.2e-22)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((x <= -2.85e-39) || !(x <= 8.2e-22)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[x, -2.85e-39], N[Not[LessEqual[x, 8.2e-22]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.85 \cdot 10^{-39} \lor \neg \left(x \leq 8.2 \cdot 10^{-22}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if x < -2.8499999999999998e-39 or 8.1999999999999999e-22 < x Initial program 9.5%
sub-neg9.5%
cos-sum47.0%
associate-+l-47.1%
fma-neg47.2%
Applied egg-rr47.2%
Taylor expanded in x around inf 47.1%
associate--r+99.3%
*-commutative99.3%
*-rgt-identity99.3%
distribute-lft-out--99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
*-commutative99.3%
Simplified99.3%
if -2.8499999999999998e-39 < x < 8.1999999999999999e-22Initial program 76.7%
diff-cos92.9%
div-inv92.9%
associate--l+92.9%
metadata-eval92.9%
div-inv92.9%
+-commutative92.9%
associate-+l+92.9%
metadata-eval92.9%
Applied egg-rr92.9%
associate-*r*92.9%
*-commutative92.9%
*-commutative92.9%
+-commutative92.9%
count-292.9%
fma-def92.9%
sub-neg92.9%
mul-1-neg92.9%
+-commutative92.9%
associate-+r+99.6%
mul-1-neg99.6%
sub-neg99.6%
+-inverses99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
neg-sub099.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5)))))
double code(double x, double eps) {
return sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
}
function code(x, eps) return Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))) end
code[x_, eps_] := N[(N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 38.9%
diff-cos45.6%
div-inv45.6%
associate--l+45.6%
metadata-eval45.6%
div-inv45.6%
+-commutative45.6%
associate-+l+45.7%
metadata-eval45.7%
Applied egg-rr45.7%
associate-*r*45.7%
*-commutative45.7%
*-commutative45.7%
+-commutative45.7%
count-245.7%
fma-def45.7%
sub-neg45.7%
mul-1-neg45.7%
+-commutative45.7%
associate-+r+78.6%
mul-1-neg78.6%
sub-neg78.6%
+-inverses78.6%
remove-double-neg78.6%
mul-1-neg78.6%
sub-neg78.6%
neg-sub078.6%
mul-1-neg78.6%
remove-double-neg78.6%
Simplified78.6%
Final simplification78.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -1e-35) (not (<= x 4.8e-25)))
(* (sin x) (* -2.0 t_0))
(* -2.0 (pow t_0 2.0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -1e-35) || !(x <= 4.8e-25)) {
tmp = sin(x) * (-2.0 * t_0);
} else {
tmp = -2.0 * pow(t_0, 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((eps * 0.5d0))
if ((x <= (-1d-35)) .or. (.not. (x <= 4.8d-25))) then
tmp = sin(x) * ((-2.0d0) * t_0)
else
tmp = (-2.0d0) * (t_0 ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
double tmp;
if ((x <= -1e-35) || !(x <= 4.8e-25)) {
tmp = Math.sin(x) * (-2.0 * t_0);
} else {
tmp = -2.0 * Math.pow(t_0, 2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -1e-35) or not (x <= 4.8e-25): tmp = math.sin(x) * (-2.0 * t_0) else: tmp = -2.0 * math.pow(t_0, 2.0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -1e-35) || !(x <= 4.8e-25)) tmp = Float64(sin(x) * Float64(-2.0 * t_0)); else tmp = Float64(-2.0 * (t_0 ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -1e-35) || ~((x <= 4.8e-25))) tmp = sin(x) * (-2.0 * t_0); else tmp = -2.0 * (t_0 ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -1e-35], N[Not[LessEqual[x, 4.8e-25]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -1 \cdot 10^{-35} \lor \neg \left(x \leq 4.8 \cdot 10^{-25}\right):\\
\;\;\;\;\sin x \cdot \left(-2 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -1.00000000000000001e-35 or 4.80000000000000018e-25 < x Initial program 8.8%
diff-cos8.5%
div-inv8.5%
associate--l+8.5%
metadata-eval8.5%
div-inv8.5%
+-commutative8.5%
associate-+l+8.8%
metadata-eval8.8%
Applied egg-rr8.8%
associate-*r*8.8%
*-commutative8.8%
*-commutative8.8%
+-commutative8.8%
count-28.8%
fma-def8.8%
sub-neg8.8%
mul-1-neg8.8%
+-commutative8.8%
associate-+r+62.6%
mul-1-neg62.6%
sub-neg62.6%
+-inverses62.6%
remove-double-neg62.6%
mul-1-neg62.6%
sub-neg62.6%
neg-sub062.6%
mul-1-neg62.6%
remove-double-neg62.6%
Simplified62.6%
Taylor expanded in eps around 0 61.2%
if -1.00000000000000001e-35 < x < 4.80000000000000018e-25Initial program 78.2%
diff-cos93.9%
div-inv93.9%
associate--l+93.9%
metadata-eval93.9%
div-inv93.9%
+-commutative93.9%
associate-+l+93.9%
metadata-eval93.9%
Applied egg-rr93.9%
associate-*r*93.9%
*-commutative93.9%
*-commutative93.9%
+-commutative93.9%
count-293.9%
fma-def93.9%
sub-neg93.9%
mul-1-neg93.9%
+-commutative93.9%
associate-+r+99.5%
mul-1-neg99.5%
sub-neg99.5%
+-inverses99.5%
remove-double-neg99.5%
mul-1-neg99.5%
sub-neg99.5%
neg-sub099.5%
mul-1-neg99.5%
remove-double-neg99.5%
Simplified99.5%
Taylor expanded in x around 0 92.8%
Final simplification74.9%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.65e-25) (not (<= eps 2.4e-17))) (- (cos eps) (cos x)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.65e-25) || !(eps <= 2.4e-17)) {
tmp = cos(eps) - cos(x);
} else {
tmp = sin(x) * -eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.65d-25)) .or. (.not. (eps <= 2.4d-17))) then
tmp = cos(eps) - cos(x)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.65e-25) || !(eps <= 2.4e-17)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.65e-25) or not (eps <= 2.4e-17): tmp = math.cos(eps) - math.cos(x) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.65e-25) || !(eps <= 2.4e-17)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.65e-25) || ~((eps <= 2.4e-17))) tmp = cos(eps) - cos(x); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.65e-25], N[Not[LessEqual[eps, 2.4e-17]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.65 \cdot 10^{-25} \lor \neg \left(\varepsilon \leq 2.4 \cdot 10^{-17}\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.6499999999999999e-25 or 2.39999999999999986e-17 < eps Initial program 53.7%
Taylor expanded in x around 0 55.8%
if -1.6499999999999999e-25 < eps < 2.39999999999999986e-17Initial program 23.9%
Taylor expanded in eps around 0 89.3%
mul-1-neg89.3%
*-commutative89.3%
distribute-rgt-neg-in89.3%
Simplified89.3%
Final simplification72.4%
(FPCore (x eps) :precision binary64 (if (<= eps -2.2e-40) (* -2.0 (pow (sin (* eps 0.5)) 2.0)) (if (<= eps 2.4e-17) (* (sin x) (- eps)) (- (cos eps) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -2.2e-40) {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
} else if (eps <= 2.4e-17) {
tmp = sin(x) * -eps;
} else {
tmp = cos(eps) - cos(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-2.2d-40)) then
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
else if (eps <= 2.4d-17) then
tmp = sin(x) * -eps
else
tmp = cos(eps) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -2.2e-40) {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
} else if (eps <= 2.4e-17) {
tmp = Math.sin(x) * -eps;
} else {
tmp = Math.cos(eps) - Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -2.2e-40: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) elif eps <= 2.4e-17: tmp = math.sin(x) * -eps else: tmp = math.cos(eps) - math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -2.2e-40) tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); elseif (eps <= 2.4e-17) tmp = Float64(sin(x) * Float64(-eps)); else tmp = Float64(cos(eps) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -2.2e-40) tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); elseif (eps <= 2.4e-17) tmp = sin(x) * -eps; else tmp = cos(eps) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -2.2e-40], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.4e-17], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.2 \cdot 10^{-40}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\mathbf{elif}\;\varepsilon \leq 2.4 \cdot 10^{-17}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\end{array}
\end{array}
if eps < -2.20000000000000009e-40Initial program 57.9%
diff-cos62.9%
div-inv62.9%
associate--l+62.9%
metadata-eval62.9%
div-inv62.9%
+-commutative62.9%
associate-+l+63.1%
metadata-eval63.1%
Applied egg-rr63.1%
associate-*r*63.1%
*-commutative63.1%
*-commutative63.1%
+-commutative63.1%
count-263.1%
fma-def63.1%
sub-neg63.1%
mul-1-neg63.1%
+-commutative63.1%
associate-+r+62.9%
mul-1-neg62.9%
sub-neg62.9%
+-inverses62.9%
remove-double-neg62.9%
mul-1-neg62.9%
sub-neg62.9%
neg-sub062.9%
mul-1-neg62.9%
remove-double-neg62.9%
Simplified62.9%
Taylor expanded in x around 0 62.2%
if -2.20000000000000009e-40 < eps < 2.39999999999999986e-17Initial program 24.0%
Taylor expanded in eps around 0 90.0%
mul-1-neg90.0%
*-commutative90.0%
distribute-rgt-neg-in90.0%
Simplified90.0%
if 2.39999999999999986e-17 < eps Initial program 49.7%
Taylor expanded in x around 0 52.2%
Final simplification73.0%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* eps 0.5)) (sin (* 0.5 (+ eps (+ x x)))))))
double code(double x, double eps) {
return -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps + (x + x)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((eps * 0.5d0)) * sin((0.5d0 * (eps + (x + x)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((eps * 0.5)) * Math.sin((0.5 * (eps + (x + x)))));
}
def code(x, eps): return -2.0 * (math.sin((eps * 0.5)) * math.sin((0.5 * (eps + (x + x)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(eps * 0.5)) * sin(Float64(0.5 * Float64(eps + Float64(x + x)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps + (x + x))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)\right)
\end{array}
Initial program 38.9%
diff-cos45.6%
*-commutative45.6%
div-inv45.6%
associate--l+45.6%
metadata-eval45.6%
div-inv45.6%
+-commutative45.6%
associate-+l+45.7%
metadata-eval45.7%
Applied egg-rr45.7%
Taylor expanded in x around 0 78.6%
Final simplification78.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000165) (not (<= eps 0.000155))) (+ -1.0 (cos eps)) (* -0.5 (pow eps 2.0))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000165) || !(eps <= 0.000155)) {
tmp = -1.0 + cos(eps);
} else {
tmp = -0.5 * pow(eps, 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.000165d0)) .or. (.not. (eps <= 0.000155d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = (-0.5d0) * (eps ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.000165) || !(eps <= 0.000155)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = -0.5 * Math.pow(eps, 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000165) or not (eps <= 0.000155): tmp = -1.0 + math.cos(eps) else: tmp = -0.5 * math.pow(eps, 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000165) || !(eps <= 0.000155)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(-0.5 * (eps ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000165) || ~((eps <= 0.000155))) tmp = -1.0 + cos(eps); else tmp = -0.5 * (eps ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000165], N[Not[LessEqual[eps, 0.000155]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000165 \lor \neg \left(\varepsilon \leq 0.000155\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\end{array}
\end{array}
if eps < -1.65e-4 or 1.55e-4 < eps Initial program 55.3%
Taylor expanded in x around 0 54.5%
if -1.65e-4 < eps < 1.55e-4Initial program 23.2%
Taylor expanded in x around 0 23.2%
Taylor expanded in eps around 0 35.5%
Final simplification44.8%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.65e-25) (not (<= eps 2.4e-17))) (+ -1.0 (cos eps)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.65e-25) || !(eps <= 2.4e-17)) {
tmp = -1.0 + cos(eps);
} else {
tmp = sin(x) * -eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.65d-25)) .or. (.not. (eps <= 2.4d-17))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.65e-25) || !(eps <= 2.4e-17)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.65e-25) or not (eps <= 2.4e-17): tmp = -1.0 + math.cos(eps) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.65e-25) || !(eps <= 2.4e-17)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.65e-25) || ~((eps <= 2.4e-17))) tmp = -1.0 + cos(eps); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.65e-25], N[Not[LessEqual[eps, 2.4e-17]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.65 \cdot 10^{-25} \lor \neg \left(\varepsilon \leq 2.4 \cdot 10^{-17}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.6499999999999999e-25 or 2.39999999999999986e-17 < eps Initial program 53.7%
Taylor expanded in x around 0 53.0%
if -1.6499999999999999e-25 < eps < 2.39999999999999986e-17Initial program 23.9%
Taylor expanded in eps around 0 89.3%
mul-1-neg89.3%
*-commutative89.3%
distribute-rgt-neg-in89.3%
Simplified89.3%
Final simplification71.0%
(FPCore (x eps) :precision binary64 (+ -1.0 (cos eps)))
double code(double x, double eps) {
return -1.0 + cos(eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-1.0d0) + cos(eps)
end function
public static double code(double x, double eps) {
return -1.0 + Math.cos(eps);
}
def code(x, eps): return -1.0 + math.cos(eps)
function code(x, eps) return Float64(-1.0 + cos(eps)) end
function tmp = code(x, eps) tmp = -1.0 + cos(eps); end
code[x_, eps_] := N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \cos \varepsilon
\end{array}
Initial program 38.9%
Taylor expanded in x around 0 38.5%
Final simplification38.5%
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
return 0.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
public static double code(double x, double eps) {
return 0.0;
}
def code(x, eps): return 0.0
function code(x, eps) return 0.0 end
function tmp = code(x, eps) tmp = 0.0; end
code[x_, eps_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 38.9%
Taylor expanded in x around 0 38.5%
Taylor expanded in eps around 0 13.4%
Final simplification13.4%
herbie shell --seed 2024017
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))