
(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 16 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 (- (sin eps))))
(if (<= eps -0.0052)
(fma (cos x) (cos eps) (- (- (cos x)) (* (sin x) (sin eps))))
(if (<= eps 0.0052)
(fma
(sin x)
t_0
(*
(cos x)
(fma 0.041666666666666664 (pow eps 4.0) (* -0.5 (* eps eps)))))
(- (fma (cos x) (cos eps) (* (sin x) t_0)) (cos x))))))
double code(double x, double eps) {
double t_0 = -sin(eps);
double tmp;
if (eps <= -0.0052) {
tmp = fma(cos(x), cos(eps), (-cos(x) - (sin(x) * sin(eps))));
} else if (eps <= 0.0052) {
tmp = fma(sin(x), t_0, (cos(x) * fma(0.041666666666666664, pow(eps, 4.0), (-0.5 * (eps * eps)))));
} else {
tmp = fma(cos(x), cos(eps), (sin(x) * t_0)) - cos(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64(-sin(eps)) tmp = 0.0 if (eps <= -0.0052) tmp = fma(cos(x), cos(eps), Float64(Float64(-cos(x)) - Float64(sin(x) * sin(eps)))); elseif (eps <= 0.0052) tmp = fma(sin(x), t_0, Float64(cos(x) * fma(0.041666666666666664, (eps ^ 4.0), Float64(-0.5 * Float64(eps * eps))))); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(x) * t_0)) - cos(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = (-N[Sin[eps], $MachinePrecision])}, If[LessEqual[eps, -0.0052], N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[((-N[Cos[x], $MachinePrecision]) - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.0052], N[(N[Sin[x], $MachinePrecision] * t$95$0 + N[(N[Cos[x], $MachinePrecision] * N[(0.041666666666666664 * N[Power[eps, 4.0], $MachinePrecision] + N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.0052:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \left(-\cos x\right) - \sin x \cdot \sin \varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 0.0052:\\
\;\;\;\;\mathsf{fma}\left(\sin x, t_0, \cos x \cdot \mathsf{fma}\left(0.041666666666666664, {\varepsilon}^{4}, -0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin x \cdot t_0\right) - \cos x\\
\end{array}
\end{array}
if eps < -0.0051999999999999998Initial program 54.6%
sub-neg54.6%
cos-sum98.9%
associate-+l-98.9%
fma-neg99.0%
Applied egg-rr99.0%
Taylor expanded in x around inf 99.0%
if -0.0051999999999999998 < eps < 0.0051999999999999998Initial program 24.1%
cos-sum25.9%
cancel-sign-sub-inv25.9%
fma-def25.9%
Applied egg-rr25.9%
Taylor expanded in x around inf 25.9%
associate--l+83.8%
*-commutative83.8%
neg-mul-183.8%
distribute-rgt-neg-in83.8%
fma-def83.8%
*-rgt-identity83.8%
distribute-lft-out--83.8%
sub-neg83.8%
metadata-eval83.8%
+-commutative83.8%
Simplified83.8%
Taylor expanded in eps around 0 99.8%
fma-def99.8%
unpow299.8%
Simplified99.8%
if 0.0051999999999999998 < eps Initial program 50.8%
cos-sum98.8%
cancel-sign-sub-inv98.8%
fma-def98.9%
Applied egg-rr98.9%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (fma (sin x) (- (sin eps)) (* (cos x) (/ (* (sin eps) (sin eps)) (- -1.0 (cos eps))))))
double code(double x, double eps) {
return fma(sin(x), -sin(eps), (cos(x) * ((sin(eps) * sin(eps)) / (-1.0 - cos(eps)))));
}
function code(x, eps) return fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(Float64(sin(eps) * sin(eps)) / Float64(-1.0 - cos(eps))))) end
code[x_, eps_] := N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(N[(N[Sin[eps], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] / N[(-1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \frac{\sin \varepsilon \cdot \sin \varepsilon}{-1 - \cos \varepsilon}\right)
\end{array}
Initial program 38.7%
cos-sum63.5%
cancel-sign-sub-inv63.5%
fma-def63.5%
Applied egg-rr63.5%
Taylor expanded in x around inf 63.5%
associate--l+91.6%
*-commutative91.6%
neg-mul-191.6%
distribute-rgt-neg-in91.6%
fma-def91.6%
*-rgt-identity91.6%
distribute-lft-out--91.6%
sub-neg91.6%
metadata-eval91.6%
+-commutative91.6%
Simplified91.6%
flip-+91.2%
metadata-eval91.2%
Applied egg-rr91.2%
1-sub-cos99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (sin eps))))
(if (<= eps -0.00021)
(fma (sin x) t_0 (* (cos x) (+ -1.0 (cos eps))))
(if (<= eps 0.000195)
(*
-2.0
(*
(+
(* -0.125 (* (sin x) (pow eps 2.0)))
(+ (sin x) (* 0.5 (* eps (cos x)))))
(sin (* eps 0.5))))
(- (fma (cos x) (cos eps) (* (sin x) t_0)) (cos x))))))
double code(double x, double eps) {
double t_0 = -sin(eps);
double tmp;
if (eps <= -0.00021) {
tmp = fma(sin(x), t_0, (cos(x) * (-1.0 + cos(eps))));
} else if (eps <= 0.000195) {
tmp = -2.0 * (((-0.125 * (sin(x) * pow(eps, 2.0))) + (sin(x) + (0.5 * (eps * cos(x))))) * sin((eps * 0.5)));
} else {
tmp = fma(cos(x), cos(eps), (sin(x) * t_0)) - cos(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64(-sin(eps)) tmp = 0.0 if (eps <= -0.00021) tmp = fma(sin(x), t_0, Float64(cos(x) * Float64(-1.0 + cos(eps)))); elseif (eps <= 0.000195) tmp = Float64(-2.0 * Float64(Float64(Float64(-0.125 * Float64(sin(x) * (eps ^ 2.0))) + Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x))))) * sin(Float64(eps * 0.5)))); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(x) * t_0)) - cos(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = (-N[Sin[eps], $MachinePrecision])}, If[LessEqual[eps, -0.00021], N[(N[Sin[x], $MachinePrecision] * t$95$0 + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.000195], N[(-2.0 * N[(N[(N[(-0.125 * N[(N[Sin[x], $MachinePrecision] * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.00021:\\
\;\;\;\;\mathsf{fma}\left(\sin x, t_0, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.000195:\\
\;\;\;\;-2 \cdot \left(\left(-0.125 \cdot \left(\sin x \cdot {\varepsilon}^{2}\right) + \left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin x \cdot t_0\right) - \cos x\\
\end{array}
\end{array}
if eps < -2.1000000000000001e-4Initial program 54.6%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def99.0%
Applied egg-rr99.0%
Taylor expanded in x around inf 98.9%
associate--l+98.9%
*-commutative98.9%
neg-mul-198.9%
distribute-rgt-neg-in98.9%
fma-def99.0%
*-rgt-identity99.0%
distribute-lft-out--99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
if -2.1000000000000001e-4 < eps < 1.94999999999999996e-4Initial program 24.1%
diff-cos40.0%
div-inv40.0%
metadata-eval40.0%
div-inv40.0%
+-commutative40.0%
metadata-eval40.0%
Applied egg-rr40.0%
*-commutative40.0%
+-commutative40.0%
associate--l+98.7%
+-inverses98.7%
distribute-lft-in98.7%
metadata-eval98.7%
*-commutative98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around -inf 98.7%
Taylor expanded in eps around 0 99.7%
if 1.94999999999999996e-4 < eps Initial program 50.8%
cos-sum98.8%
cancel-sign-sub-inv98.8%
fma-def98.9%
Applied egg-rr98.9%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.00019)
(fma (cos x) (cos eps) (- (- (cos x)) (* (sin x) (sin eps))))
(if (<= eps 0.00018)
(*
-2.0
(*
(+
(* -0.125 (* (sin x) (pow eps 2.0)))
(+ (sin x) (* 0.5 (* eps (cos x)))))
(sin (* eps 0.5))))
(- (fma (cos x) (cos eps) (* (sin x) (- (sin eps)))) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.00019) {
tmp = fma(cos(x), cos(eps), (-cos(x) - (sin(x) * sin(eps))));
} else if (eps <= 0.00018) {
tmp = -2.0 * (((-0.125 * (sin(x) * pow(eps, 2.0))) + (sin(x) + (0.5 * (eps * cos(x))))) * sin((eps * 0.5)));
} else {
tmp = fma(cos(x), cos(eps), (sin(x) * -sin(eps))) - cos(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.00019) tmp = fma(cos(x), cos(eps), Float64(Float64(-cos(x)) - Float64(sin(x) * sin(eps)))); elseif (eps <= 0.00018) tmp = Float64(-2.0 * Float64(Float64(Float64(-0.125 * Float64(sin(x) * (eps ^ 2.0))) + Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x))))) * sin(Float64(eps * 0.5)))); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(x) * Float64(-sin(eps)))) - cos(x)); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.00019], N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[((-N[Cos[x], $MachinePrecision]) - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00018], N[(-2.0 * N[(N[(N[(-0.125 * N[(N[Sin[x], $MachinePrecision] * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00019:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \left(-\cos x\right) - \sin x \cdot \sin \varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00018:\\
\;\;\;\;-2 \cdot \left(\left(-0.125 \cdot \left(\sin x \cdot {\varepsilon}^{2}\right) + \left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin x \cdot \left(-\sin \varepsilon\right)\right) - \cos x\\
\end{array}
\end{array}
if eps < -1.9000000000000001e-4Initial program 54.6%
sub-neg54.6%
cos-sum98.9%
associate-+l-98.9%
fma-neg99.0%
Applied egg-rr99.0%
Taylor expanded in x around inf 99.0%
if -1.9000000000000001e-4 < eps < 1.80000000000000011e-4Initial program 24.1%
diff-cos40.0%
div-inv40.0%
metadata-eval40.0%
div-inv40.0%
+-commutative40.0%
metadata-eval40.0%
Applied egg-rr40.0%
*-commutative40.0%
+-commutative40.0%
associate--l+98.7%
+-inverses98.7%
distribute-lft-in98.7%
metadata-eval98.7%
*-commutative98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around -inf 98.7%
Taylor expanded in eps around 0 99.7%
if 1.80000000000000011e-4 < eps Initial program 50.8%
cos-sum98.8%
cancel-sign-sub-inv98.8%
fma-def98.9%
Applied egg-rr98.9%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00021) (not (<= eps 0.00018)))
(fma (sin x) (- (sin eps)) (* (cos x) (+ -1.0 (cos eps))))
(*
-2.0
(*
(+
(* -0.125 (* (sin x) (pow eps 2.0)))
(+ (sin x) (* 0.5 (* eps (cos x)))))
(sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00021) || !(eps <= 0.00018)) {
tmp = fma(sin(x), -sin(eps), (cos(x) * (-1.0 + cos(eps))));
} else {
tmp = -2.0 * (((-0.125 * (sin(x) * pow(eps, 2.0))) + (sin(x) + (0.5 * (eps * cos(x))))) * sin((eps * 0.5)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -0.00021) || !(eps <= 0.00018)) tmp = fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(-1.0 + cos(eps)))); else tmp = Float64(-2.0 * Float64(Float64(Float64(-0.125 * Float64(sin(x) * (eps ^ 2.0))) + Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x))))) * sin(Float64(eps * 0.5)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00021], N[Not[LessEqual[eps, 0.00018]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(N[(-0.125 * N[(N[Sin[x], $MachinePrecision] * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00021 \lor \neg \left(\varepsilon \leq 0.00018\right):\\
\;\;\;\;\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(-0.125 \cdot \left(\sin x \cdot {\varepsilon}^{2}\right) + \left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -2.1000000000000001e-4 or 1.80000000000000011e-4 < eps Initial program 52.5%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 98.9%
associate--l+98.9%
*-commutative98.9%
neg-mul-198.9%
distribute-rgt-neg-in98.9%
fma-def98.9%
*-rgt-identity98.9%
distribute-lft-out--98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
if -2.1000000000000001e-4 < eps < 1.80000000000000011e-4Initial program 24.1%
diff-cos40.0%
div-inv40.0%
metadata-eval40.0%
div-inv40.0%
+-commutative40.0%
metadata-eval40.0%
Applied egg-rr40.0%
*-commutative40.0%
+-commutative40.0%
associate--l+98.7%
+-inverses98.7%
distribute-lft-in98.7%
metadata-eval98.7%
*-commutative98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around -inf 98.7%
Taylor expanded in eps around 0 99.7%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (sin eps))))
(if (or (<= eps -0.00014) (not (<= eps 0.00014)))
(fma (sin x) t_0 (* (cos x) (+ -1.0 (cos eps))))
(fma (sin x) t_0 (* (cos x) (* -0.5 (* eps eps)))))))
double code(double x, double eps) {
double t_0 = -sin(eps);
double tmp;
if ((eps <= -0.00014) || !(eps <= 0.00014)) {
tmp = fma(sin(x), t_0, (cos(x) * (-1.0 + cos(eps))));
} else {
tmp = fma(sin(x), t_0, (cos(x) * (-0.5 * (eps * eps))));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-sin(eps)) tmp = 0.0 if ((eps <= -0.00014) || !(eps <= 0.00014)) tmp = fma(sin(x), t_0, Float64(cos(x) * Float64(-1.0 + cos(eps)))); else tmp = fma(sin(x), t_0, Float64(cos(x) * Float64(-0.5 * Float64(eps * eps)))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = (-N[Sin[eps], $MachinePrecision])}, If[Or[LessEqual[eps, -0.00014], N[Not[LessEqual[eps, 0.00014]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * t$95$0 + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * t$95$0 + N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.00014 \lor \neg \left(\varepsilon \leq 0.00014\right):\\
\;\;\;\;\mathsf{fma}\left(\sin x, t_0, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin x, t_0, \cos x \cdot \left(-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\right)\right)\\
\end{array}
\end{array}
if eps < -1.3999999999999999e-4 or 1.3999999999999999e-4 < eps Initial program 52.5%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 98.9%
associate--l+98.9%
*-commutative98.9%
neg-mul-198.9%
distribute-rgt-neg-in98.9%
fma-def98.9%
*-rgt-identity98.9%
distribute-lft-out--98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
if -1.3999999999999999e-4 < eps < 1.3999999999999999e-4Initial program 24.1%
cos-sum25.9%
cancel-sign-sub-inv25.9%
fma-def25.9%
Applied egg-rr25.9%
Taylor expanded in x around inf 25.9%
associate--l+83.8%
*-commutative83.8%
neg-mul-183.8%
distribute-rgt-neg-in83.8%
fma-def83.8%
*-rgt-identity83.8%
distribute-lft-out--83.8%
sub-neg83.8%
metadata-eval83.8%
+-commutative83.8%
Simplified83.8%
Taylor expanded in eps around 0 99.7%
unpow299.7%
Simplified99.7%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (cos (+ x eps)) (cos x))))
(if (<= t_0 -0.0005)
t_0
(- (* -0.5 (* eps (* eps (cos x)))) (* (sin x) eps)))))
double code(double x, double eps) {
double t_0 = cos((x + eps)) - cos(x);
double tmp;
if (t_0 <= -0.0005) {
tmp = t_0;
} else {
tmp = (-0.5 * (eps * (eps * cos(x)))) - (sin(x) * eps);
}
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 = cos((x + eps)) - cos(x)
if (t_0 <= (-0.0005d0)) then
tmp = t_0
else
tmp = ((-0.5d0) * (eps * (eps * cos(x)))) - (sin(x) * eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos((x + eps)) - Math.cos(x);
double tmp;
if (t_0 <= -0.0005) {
tmp = t_0;
} else {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) - (Math.sin(x) * eps);
}
return tmp;
}
def code(x, eps): t_0 = math.cos((x + eps)) - math.cos(x) tmp = 0 if t_0 <= -0.0005: tmp = t_0 else: tmp = (-0.5 * (eps * (eps * math.cos(x)))) - (math.sin(x) * eps) return tmp
function code(x, eps) t_0 = Float64(cos(Float64(x + eps)) - cos(x)) tmp = 0.0 if (t_0 <= -0.0005) tmp = t_0; else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) - Float64(sin(x) * eps)); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos((x + eps)) - cos(x); tmp = 0.0; if (t_0 <= -0.0005) tmp = t_0; else tmp = (-0.5 * (eps * (eps * cos(x)))) - (sin(x) * eps); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.0005], t$95$0, N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(x + \varepsilon\right) - \cos x\\
\mathbf{if}\;t_0 \leq -0.0005:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) - \sin x \cdot \varepsilon\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -5.0000000000000001e-4Initial program 76.6%
if -5.0000000000000001e-4 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 19.2%
Taylor expanded in eps around 0 73.9%
mul-1-neg73.9%
unsub-neg73.9%
unpow273.9%
associate-*l*73.9%
Simplified73.9%
Final simplification74.9%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.00014) (not (<= eps 0.00014))) (- (* (cos x) (+ -1.0 (cos eps))) (* (sin x) (sin eps))) (fma (sin x) (- (sin eps)) (* (cos x) (* -0.5 (* eps eps))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00014) || !(eps <= 0.00014)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(x) * sin(eps));
} else {
tmp = fma(sin(x), -sin(eps), (cos(x) * (-0.5 * (eps * eps))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -0.00014) || !(eps <= 0.00014)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(x) * sin(eps))); else tmp = fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(-0.5 * Float64(eps * eps)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00014], N[Not[LessEqual[eps, 0.00014]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00014 \lor \neg \left(\varepsilon \leq 0.00014\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin x \cdot \sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \left(-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\right)\right)\\
\end{array}
\end{array}
if eps < -1.3999999999999999e-4 or 1.3999999999999999e-4 < eps Initial program 52.5%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 98.9%
associate--l+98.9%
*-commutative98.9%
neg-mul-198.9%
distribute-rgt-neg-in98.9%
fma-def98.9%
*-rgt-identity98.9%
distribute-lft-out--98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
fma-udef98.9%
*-commutative98.9%
Applied egg-rr98.9%
if -1.3999999999999999e-4 < eps < 1.3999999999999999e-4Initial program 24.1%
cos-sum25.9%
cancel-sign-sub-inv25.9%
fma-def25.9%
Applied egg-rr25.9%
Taylor expanded in x around inf 25.9%
associate--l+83.8%
*-commutative83.8%
neg-mul-183.8%
distribute-rgt-neg-in83.8%
fma-def83.8%
*-rgt-identity83.8%
distribute-lft-out--83.8%
sub-neg83.8%
metadata-eval83.8%
+-commutative83.8%
Simplified83.8%
Taylor expanded in eps around 0 99.7%
unpow299.7%
Simplified99.7%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00014) (not (<= eps 0.00014)))
(- (* (cos x) (+ -1.0 (cos eps))) (* (sin x) (sin eps)))
(+
(* -0.5 (* eps (* eps (cos x))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00014) || !(eps <= 0.00014)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(x) * sin(eps));
} else {
tmp = (-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - eps));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.00014d0)) .or. (.not. (eps <= 0.00014d0))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(x) * sin(eps))
else
tmp = ((-0.5d0) * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666d0 * (eps ** 3.0d0)) - eps))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.00014) || !(eps <= 0.00014)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(x) * Math.sin(eps));
} else {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) + (Math.sin(x) * ((0.16666666666666666 * Math.pow(eps, 3.0)) - eps));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00014) or not (eps <= 0.00014): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(x) * math.sin(eps)) else: tmp = (-0.5 * (eps * (eps * math.cos(x)))) + (math.sin(x) * ((0.16666666666666666 * math.pow(eps, 3.0)) - eps)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00014) || !(eps <= 0.00014)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(x) * sin(eps))); else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00014) || ~((eps <= 0.00014))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(x) * sin(eps)); else tmp = (-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666 * (eps ^ 3.0)) - eps)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00014], N[Not[LessEqual[eps, 0.00014]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00014 \lor \neg \left(\varepsilon \leq 0.00014\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin x \cdot \sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.3999999999999999e-4 or 1.3999999999999999e-4 < eps Initial program 52.5%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 98.9%
associate--l+98.9%
*-commutative98.9%
neg-mul-198.9%
distribute-rgt-neg-in98.9%
fma-def98.9%
*-rgt-identity98.9%
distribute-lft-out--98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
fma-udef98.9%
*-commutative98.9%
Applied egg-rr98.9%
if -1.3999999999999999e-4 < eps < 1.3999999999999999e-4Initial program 24.1%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
associate-+l+99.7%
unpow299.7%
associate-*l*99.7%
associate-*r*99.7%
associate-*r*99.7%
distribute-rgt-out99.7%
mul-1-neg99.7%
Simplified99.7%
Taylor expanded in x around inf 99.7%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (cos (+ x eps)) (cos x))))
(if (<= t_0 -0.0005)
t_0
(* -2.0 (* (* eps 0.5) (sin (* 0.5 (- eps (* x -2.0)))))))))
double code(double x, double eps) {
double t_0 = cos((x + eps)) - cos(x);
double tmp;
if (t_0 <= -0.0005) {
tmp = t_0;
} else {
tmp = -2.0 * ((eps * 0.5) * sin((0.5 * (eps - (x * -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 = cos((x + eps)) - cos(x)
if (t_0 <= (-0.0005d0)) then
tmp = t_0
else
tmp = (-2.0d0) * ((eps * 0.5d0) * sin((0.5d0 * (eps - (x * (-2.0d0))))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos((x + eps)) - Math.cos(x);
double tmp;
if (t_0 <= -0.0005) {
tmp = t_0;
} else {
tmp = -2.0 * ((eps * 0.5) * Math.sin((0.5 * (eps - (x * -2.0)))));
}
return tmp;
}
def code(x, eps): t_0 = math.cos((x + eps)) - math.cos(x) tmp = 0 if t_0 <= -0.0005: tmp = t_0 else: tmp = -2.0 * ((eps * 0.5) * math.sin((0.5 * (eps - (x * -2.0))))) return tmp
function code(x, eps) t_0 = Float64(cos(Float64(x + eps)) - cos(x)) tmp = 0.0 if (t_0 <= -0.0005) tmp = t_0; else tmp = Float64(-2.0 * Float64(Float64(eps * 0.5) * sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))))); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos((x + eps)) - cos(x); tmp = 0.0; if (t_0 <= -0.0005) tmp = t_0; else tmp = -2.0 * ((eps * 0.5) * sin((0.5 * (eps - (x * -2.0))))); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.0005], t$95$0, N[(-2.0 * N[(N[(eps * 0.5), $MachinePrecision] * N[Sin[N[(0.5 * N[(eps - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(x + \varepsilon\right) - \cos x\\
\mathbf{if}\;t_0 \leq -0.0005:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(\varepsilon \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -5.0000000000000001e-4Initial program 76.6%
if -5.0000000000000001e-4 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 19.2%
diff-cos30.3%
div-inv30.3%
metadata-eval30.3%
div-inv30.3%
+-commutative30.3%
metadata-eval30.3%
Applied egg-rr30.3%
*-commutative30.3%
+-commutative30.3%
associate--l+75.0%
+-inverses75.0%
distribute-lft-in75.0%
metadata-eval75.0%
*-commutative75.0%
+-commutative75.0%
Simplified75.0%
Taylor expanded in x around -inf 75.0%
Taylor expanded in eps around 0 73.4%
Final simplification74.5%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* eps 0.5)) (sin (* 0.5 (+ x (+ x eps)))))))
double code(double x, double eps) {
return -2.0 * (sin((eps * 0.5)) * sin((0.5 * (x + (x + eps)))));
}
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 * (x + (x + eps)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((eps * 0.5)) * Math.sin((0.5 * (x + (x + eps)))));
}
def code(x, eps): return -2.0 * (math.sin((eps * 0.5)) * math.sin((0.5 * (x + (x + eps)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(eps * 0.5)) * sin(Float64(0.5 * Float64(x + Float64(x + eps)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((eps * 0.5)) * sin((0.5 * (x + (x + eps))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(x + N[(x + eps), $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(x + \left(x + \varepsilon\right)\right)\right)\right)
\end{array}
Initial program 38.7%
diff-cos45.9%
div-inv45.9%
metadata-eval45.9%
div-inv45.9%
+-commutative45.9%
metadata-eval45.9%
Applied egg-rr45.9%
*-commutative45.9%
+-commutative45.9%
associate--l+75.4%
+-inverses75.4%
distribute-lft-in75.4%
metadata-eval75.4%
*-commutative75.4%
+-commutative75.4%
Simplified75.4%
add-exp-log56.9%
*-commutative56.9%
+-commutative56.9%
+-rgt-identity56.9%
Applied egg-rr56.9%
add-exp-log75.4%
+-commutative75.4%
Applied egg-rr75.4%
Final simplification75.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0023) (not (<= eps 0.00375))) (- (cos eps) (cos x)) (* -2.0 (* (* eps 0.5) (sin (* 0.5 (- eps (* x -2.0))))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0023) || !(eps <= 0.00375)) {
tmp = cos(eps) - cos(x);
} else {
tmp = -2.0 * ((eps * 0.5) * sin((0.5 * (eps - (x * -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.0023d0)) .or. (.not. (eps <= 0.00375d0))) then
tmp = cos(eps) - cos(x)
else
tmp = (-2.0d0) * ((eps * 0.5d0) * sin((0.5d0 * (eps - (x * (-2.0d0))))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0023) || !(eps <= 0.00375)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = -2.0 * ((eps * 0.5) * Math.sin((0.5 * (eps - (x * -2.0)))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0023) or not (eps <= 0.00375): tmp = math.cos(eps) - math.cos(x) else: tmp = -2.0 * ((eps * 0.5) * math.sin((0.5 * (eps - (x * -2.0))))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0023) || !(eps <= 0.00375)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(-2.0 * Float64(Float64(eps * 0.5) * sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0023) || ~((eps <= 0.00375))) tmp = cos(eps) - cos(x); else tmp = -2.0 * ((eps * 0.5) * sin((0.5 * (eps - (x * -2.0))))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0023], N[Not[LessEqual[eps, 0.00375]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(eps * 0.5), $MachinePrecision] * N[Sin[N[(0.5 * N[(eps - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0023 \lor \neg \left(\varepsilon \leq 0.00375\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(\varepsilon \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right)\right)\\
\end{array}
\end{array}
if eps < -0.0023 or 0.0037499999999999999 < eps Initial program 52.5%
Taylor expanded in x around 0 54.3%
if -0.0023 < eps < 0.0037499999999999999Initial program 24.1%
diff-cos40.0%
div-inv40.0%
metadata-eval40.0%
div-inv40.0%
+-commutative40.0%
metadata-eval40.0%
Applied egg-rr40.0%
*-commutative40.0%
+-commutative40.0%
associate--l+98.7%
+-inverses98.7%
distribute-lft-in98.7%
metadata-eval98.7%
*-commutative98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around -inf 98.7%
Taylor expanded in eps around 0 98.7%
Final simplification75.8%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.00165) (not (<= eps 0.00176))) (+ -1.0 (cos eps)) (* -2.0 (* (* eps 0.5) (sin (* 0.5 (- eps (* x -2.0))))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00165) || !(eps <= 0.00176)) {
tmp = -1.0 + cos(eps);
} else {
tmp = -2.0 * ((eps * 0.5) * sin((0.5 * (eps - (x * -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.00165d0)) .or. (.not. (eps <= 0.00176d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = (-2.0d0) * ((eps * 0.5d0) * sin((0.5d0 * (eps - (x * (-2.0d0))))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.00165) || !(eps <= 0.00176)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = -2.0 * ((eps * 0.5) * Math.sin((0.5 * (eps - (x * -2.0)))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00165) or not (eps <= 0.00176): tmp = -1.0 + math.cos(eps) else: tmp = -2.0 * ((eps * 0.5) * math.sin((0.5 * (eps - (x * -2.0))))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00165) || !(eps <= 0.00176)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(-2.0 * Float64(Float64(eps * 0.5) * sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00165) || ~((eps <= 0.00176))) tmp = -1.0 + cos(eps); else tmp = -2.0 * ((eps * 0.5) * sin((0.5 * (eps - (x * -2.0))))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00165], N[Not[LessEqual[eps, 0.00176]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(eps * 0.5), $MachinePrecision] * N[Sin[N[(0.5 * N[(eps - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00165 \lor \neg \left(\varepsilon \leq 0.00176\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(\varepsilon \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right)\right)\\
\end{array}
\end{array}
if eps < -0.00165 or 0.00176000000000000006 < eps Initial program 52.5%
Taylor expanded in x around 0 53.1%
if -0.00165 < eps < 0.00176000000000000006Initial program 24.1%
diff-cos40.0%
div-inv40.0%
metadata-eval40.0%
div-inv40.0%
+-commutative40.0%
metadata-eval40.0%
Applied egg-rr40.0%
*-commutative40.0%
+-commutative40.0%
associate--l+98.7%
+-inverses98.7%
distribute-lft-in98.7%
metadata-eval98.7%
*-commutative98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around -inf 98.7%
Taylor expanded in eps around 0 98.7%
Final simplification75.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.4e-7) (not (<= eps 5e-5))) (+ -1.0 (cos eps)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.4e-7) || !(eps <= 5e-5)) {
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 <= (-3.4d-7)) .or. (.not. (eps <= 5d-5))) 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 <= -3.4e-7) || !(eps <= 5e-5)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.4e-7) or not (eps <= 5e-5): tmp = -1.0 + math.cos(eps) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.4e-7) || !(eps <= 5e-5)) 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 <= -3.4e-7) || ~((eps <= 5e-5))) tmp = -1.0 + cos(eps); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.4e-7], N[Not[LessEqual[eps, 5e-5]], $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 -3.4 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 5 \cdot 10^{-5}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -3.39999999999999974e-7 or 5.00000000000000024e-5 < eps Initial program 52.5%
Taylor expanded in x around 0 53.1%
if -3.39999999999999974e-7 < eps < 5.00000000000000024e-5Initial program 24.1%
Taylor expanded in eps around 0 83.3%
associate-*r*83.3%
mul-1-neg83.3%
Simplified83.3%
Final simplification67.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -2.55e-11) (not (<= eps 0.00014))) (+ -1.0 (cos eps)) (* eps (* eps -0.5))))
double code(double x, double eps) {
double tmp;
if ((eps <= -2.55e-11) || !(eps <= 0.00014)) {
tmp = -1.0 + cos(eps);
} else {
tmp = eps * (eps * -0.5);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-2.55d-11)) .or. (.not. (eps <= 0.00014d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = eps * (eps * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -2.55e-11) || !(eps <= 0.00014)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * (eps * -0.5);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -2.55e-11) or not (eps <= 0.00014): tmp = -1.0 + math.cos(eps) else: tmp = eps * (eps * -0.5) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -2.55e-11) || !(eps <= 0.00014)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(eps * Float64(eps * -0.5)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -2.55e-11) || ~((eps <= 0.00014))) tmp = -1.0 + cos(eps); else tmp = eps * (eps * -0.5); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -2.55e-11], N[Not[LessEqual[eps, 0.00014]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.55 \cdot 10^{-11} \lor \neg \left(\varepsilon \leq 0.00014\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\end{array}
\end{array}
if eps < -2.54999999999999992e-11 or 1.3999999999999999e-4 < eps Initial program 52.1%
Taylor expanded in x around 0 52.7%
if -2.54999999999999992e-11 < eps < 1.3999999999999999e-4Initial program 24.3%
Taylor expanded in x around 0 24.4%
Taylor expanded in eps around 0 39.2%
*-commutative39.2%
unpow239.2%
associate-*l*39.2%
Simplified39.2%
Final simplification46.2%
(FPCore (x eps) :precision binary64 (* eps (* eps -0.5)))
double code(double x, double eps) {
return eps * (eps * -0.5);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * (eps * (-0.5d0))
end function
public static double code(double x, double eps) {
return eps * (eps * -0.5);
}
def code(x, eps): return eps * (eps * -0.5)
function code(x, eps) return Float64(eps * Float64(eps * -0.5)) end
function tmp = code(x, eps) tmp = eps * (eps * -0.5); end
code[x_, eps_] := N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)
\end{array}
Initial program 38.7%
Taylor expanded in x around 0 39.1%
Taylor expanded in eps around 0 20.7%
*-commutative20.7%
unpow220.7%
associate-*l*20.7%
Simplified20.7%
Final simplification20.7%
herbie shell --seed 2023242
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))