
(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 17 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
(if (<= eps -0.0028)
(fma (cos x) (cos eps) (- (fma (sin eps) (sin x) (cos x))))
(if (<= eps 0.0024)
(-
(+
(* 0.16666666666666666 (* (sin x) (pow eps 3.0)))
(*
(cos x)
(+ (* -0.5 (pow eps 2.0)) (* 0.041666666666666664 (pow eps 4.0)))))
(* eps (sin x)))
(- (fma (cos x) (cos eps) (* (sin eps) (- (sin x)))) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0028) {
tmp = fma(cos(x), cos(eps), -fma(sin(eps), sin(x), cos(x)));
} else if (eps <= 0.0024) {
tmp = ((0.16666666666666666 * (sin(x) * pow(eps, 3.0))) + (cos(x) * ((-0.5 * pow(eps, 2.0)) + (0.041666666666666664 * pow(eps, 4.0))))) - (eps * sin(x));
} else {
tmp = fma(cos(x), cos(eps), (sin(eps) * -sin(x))) - cos(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.0028) tmp = fma(cos(x), cos(eps), Float64(-fma(sin(eps), sin(x), cos(x)))); elseif (eps <= 0.0024) tmp = Float64(Float64(Float64(0.16666666666666666 * Float64(sin(x) * (eps ^ 3.0))) + Float64(cos(x) * Float64(Float64(-0.5 * (eps ^ 2.0)) + Float64(0.041666666666666664 * (eps ^ 4.0))))) - Float64(eps * sin(x))); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(eps) * Float64(-sin(x)))) - cos(x)); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.0028], N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + (-N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision] + N[Cos[x], $MachinePrecision]), $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 0.0024], N[(N[(N[(0.16666666666666666 * N[(N[Sin[x], $MachinePrecision] * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.041666666666666664 * N[Power[eps, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0028:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, -\mathsf{fma}\left(\sin \varepsilon, \sin x, \cos x\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.0024:\\
\;\;\;\;\left(0.16666666666666666 \cdot \left(\sin x \cdot {\varepsilon}^{3}\right) + \cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2} + 0.041666666666666664 \cdot {\varepsilon}^{4}\right)\right) - \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin \varepsilon \cdot \left(-\sin x\right)\right) - \cos x\\
\end{array}
\end{array}
if eps < -0.00279999999999999997Initial program 42.1%
sub-neg42.1%
+-commutative42.1%
cos-sum98.3%
cancel-sign-sub-inv98.3%
associate-+r+98.5%
*-commutative98.5%
Applied egg-rr98.5%
+-commutative98.5%
unsub-neg98.5%
Applied egg-rr98.5%
associate-+l-98.4%
fma-neg98.5%
*-commutative98.5%
cancel-sign-sub98.5%
+-commutative98.5%
*-commutative98.5%
fma-def98.5%
Applied egg-rr98.5%
if -0.00279999999999999997 < eps < 0.00239999999999999979Initial program 20.6%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
associate-+r+99.8%
+-commutative99.8%
*-commutative99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
Simplified99.8%
if 0.00239999999999999979 < eps Initial program 57.1%
cos-sum98.7%
fma-neg98.8%
distribute-lft-neg-in98.8%
*-commutative98.8%
Applied egg-rr98.8%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.0025)
(- (- (* (cos x) (cos eps)) (cos x)) (* (sin eps) (sin x)))
(if (<= eps 0.0024)
(-
(+
(* 0.16666666666666666 (* (sin x) (pow eps 3.0)))
(*
(cos x)
(+ (* -0.5 (pow eps 2.0)) (* 0.041666666666666664 (pow eps 4.0)))))
(* eps (sin x)))
(- (fma (cos x) (cos eps) (* (sin eps) (- (sin x)))) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0025) {
tmp = ((cos(x) * cos(eps)) - cos(x)) - (sin(eps) * sin(x));
} else if (eps <= 0.0024) {
tmp = ((0.16666666666666666 * (sin(x) * pow(eps, 3.0))) + (cos(x) * ((-0.5 * pow(eps, 2.0)) + (0.041666666666666664 * pow(eps, 4.0))))) - (eps * sin(x));
} else {
tmp = fma(cos(x), cos(eps), (sin(eps) * -sin(x))) - cos(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.0025) tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - cos(x)) - Float64(sin(eps) * sin(x))); elseif (eps <= 0.0024) tmp = Float64(Float64(Float64(0.16666666666666666 * Float64(sin(x) * (eps ^ 3.0))) + Float64(cos(x) * Float64(Float64(-0.5 * (eps ^ 2.0)) + Float64(0.041666666666666664 * (eps ^ 4.0))))) - Float64(eps * sin(x))); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(eps) * Float64(-sin(x)))) - cos(x)); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.0025], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.0024], N[(N[(N[(0.16666666666666666 * N[(N[Sin[x], $MachinePrecision] * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.041666666666666664 * N[Power[eps, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0025:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \cos x\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{elif}\;\varepsilon \leq 0.0024:\\
\;\;\;\;\left(0.16666666666666666 \cdot \left(\sin x \cdot {\varepsilon}^{3}\right) + \cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2} + 0.041666666666666664 \cdot {\varepsilon}^{4}\right)\right) - \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin \varepsilon \cdot \left(-\sin x\right)\right) - \cos x\\
\end{array}
\end{array}
if eps < -0.00250000000000000005Initial program 42.1%
sub-neg42.1%
+-commutative42.1%
cos-sum98.3%
cancel-sign-sub-inv98.3%
associate-+r+98.5%
*-commutative98.5%
Applied egg-rr98.5%
+-commutative98.5%
unsub-neg98.5%
Applied egg-rr98.5%
if -0.00250000000000000005 < eps < 0.00239999999999999979Initial program 20.6%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
associate-+r+99.8%
+-commutative99.8%
*-commutative99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
Simplified99.8%
if 0.00239999999999999979 < eps Initial program 57.1%
cos-sum98.7%
fma-neg98.8%
distribute-lft-neg-in98.8%
*-commutative98.8%
Applied egg-rr98.8%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(if (<= eps -4.1e-5)
(- (- (* (cos x) (cos eps)) (cos x)) (* (sin eps) (sin x)))
(if (<= eps 3e-5)
(- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))
(- (fma (cos x) (cos eps) (* (sin eps) (- (sin x)))) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -4.1e-5) {
tmp = ((cos(x) * cos(eps)) - cos(x)) - (sin(eps) * sin(x));
} else if (eps <= 3e-5) {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (eps * sin(x));
} else {
tmp = fma(cos(x), cos(eps), (sin(eps) * -sin(x))) - cos(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -4.1e-5) tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - cos(x)) - Float64(sin(eps) * sin(x))); elseif (eps <= 3e-5) tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(eps * sin(x))); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(eps) * Float64(-sin(x)))) - cos(x)); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -4.1e-5], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3e-5], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.1 \cdot 10^{-5}:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \cos x\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{elif}\;\varepsilon \leq 3 \cdot 10^{-5}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin \varepsilon \cdot \left(-\sin x\right)\right) - \cos x\\
\end{array}
\end{array}
if eps < -4.10000000000000005e-5Initial program 42.1%
sub-neg42.1%
+-commutative42.1%
cos-sum98.3%
cancel-sign-sub-inv98.3%
associate-+r+98.5%
*-commutative98.5%
Applied egg-rr98.5%
+-commutative98.5%
unsub-neg98.5%
Applied egg-rr98.5%
if -4.10000000000000005e-5 < eps < 3.00000000000000008e-5Initial program 20.6%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
if 3.00000000000000008e-5 < eps Initial program 57.1%
cos-sum98.7%
fma-neg98.8%
distribute-lft-neg-in98.8%
*-commutative98.8%
Applied egg-rr98.8%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.1e-5) (not (<= eps 3.6e-5))) (fma (+ (cos eps) -1.0) (cos x) (* (sin eps) (- (sin x)))) (- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.1e-5) || !(eps <= 3.6e-5)) {
tmp = fma((cos(eps) + -1.0), cos(x), (sin(eps) * -sin(x)));
} else {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (eps * sin(x));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -4.1e-5) || !(eps <= 3.6e-5)) tmp = fma(Float64(cos(eps) + -1.0), cos(x), Float64(sin(eps) * Float64(-sin(x)))); else tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(eps * sin(x))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -4.1e-5], N[Not[LessEqual[eps, 3.6e-5]], $MachinePrecision]], N[(N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.1 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 3.6 \cdot 10^{-5}\right):\\
\;\;\;\;\mathsf{fma}\left(\cos \varepsilon + -1, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -4.10000000000000005e-5 or 3.60000000000000009e-5 < eps Initial program 50.7%
sub-neg50.7%
cos-sum98.5%
cancel-sign-sub-inv98.5%
associate-+l+98.6%
*-commutative98.6%
Applied egg-rr98.6%
+-commutative98.6%
distribute-rgt-neg-out98.6%
*-commutative98.6%
unsub-neg98.6%
associate-+r-98.7%
*-commutative98.7%
neg-mul-198.7%
distribute-rgt-out98.6%
*-commutative98.6%
Simplified98.6%
*-commutative98.6%
fma-neg98.6%
distribute-rgt-neg-in98.6%
Applied egg-rr98.6%
if -4.10000000000000005e-5 < eps < 3.60000000000000009e-5Initial program 20.6%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(if (<= eps -3.3e-5)
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin eps) (sin x))))
(if (<= eps 4.2e-5)
(- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))
(fma (+ (cos eps) -1.0) (cos x) (* (sin eps) (- (sin x)))))))
double code(double x, double eps) {
double tmp;
if (eps <= -3.3e-5) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(eps) * sin(x)));
} else if (eps <= 4.2e-5) {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (eps * sin(x));
} else {
tmp = fma((cos(eps) + -1.0), cos(x), (sin(eps) * -sin(x)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -3.3e-5) tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(eps) * sin(x)))); elseif (eps <= 4.2e-5) tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(eps * sin(x))); else tmp = fma(Float64(cos(eps) + -1.0), cos(x), Float64(sin(eps) * Float64(-sin(x)))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -3.3e-5], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.2e-5], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.3 \cdot 10^{-5}:\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin \varepsilon \cdot \sin x\right)\\
\mathbf{elif}\;\varepsilon \leq 4.2 \cdot 10^{-5}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos \varepsilon + -1, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\end{array}
\end{array}
if eps < -3.3000000000000003e-5Initial program 42.1%
sub-neg42.1%
+-commutative42.1%
cos-sum98.3%
cancel-sign-sub-inv98.3%
associate-+r+98.5%
*-commutative98.5%
Applied egg-rr98.5%
+-commutative98.5%
+-commutative98.5%
associate-+r+98.3%
+-commutative98.3%
*-commutative98.3%
cancel-sign-sub-inv98.3%
sub-neg98.3%
associate--l-98.4%
+-commutative98.4%
*-commutative98.4%
Applied egg-rr98.4%
if -3.3000000000000003e-5 < eps < 4.19999999999999977e-5Initial program 20.6%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
if 4.19999999999999977e-5 < eps Initial program 57.1%
sub-neg57.1%
cos-sum98.7%
cancel-sign-sub-inv98.7%
associate-+l+98.7%
*-commutative98.7%
Applied egg-rr98.7%
+-commutative98.7%
distribute-rgt-neg-out98.7%
*-commutative98.7%
unsub-neg98.7%
associate-+r-98.8%
*-commutative98.8%
neg-mul-198.8%
distribute-rgt-out98.8%
*-commutative98.8%
Simplified98.8%
*-commutative98.8%
fma-neg98.8%
distribute-rgt-neg-in98.8%
Applied egg-rr98.8%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(if (<= eps -3.8e-5)
(- (- (* (cos x) (cos eps)) (cos x)) (* (sin eps) (sin x)))
(if (<= eps 2.8e-5)
(- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))
(fma (+ (cos eps) -1.0) (cos x) (* (sin eps) (- (sin x)))))))
double code(double x, double eps) {
double tmp;
if (eps <= -3.8e-5) {
tmp = ((cos(x) * cos(eps)) - cos(x)) - (sin(eps) * sin(x));
} else if (eps <= 2.8e-5) {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (eps * sin(x));
} else {
tmp = fma((cos(eps) + -1.0), cos(x), (sin(eps) * -sin(x)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -3.8e-5) tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - cos(x)) - Float64(sin(eps) * sin(x))); elseif (eps <= 2.8e-5) tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(eps * sin(x))); else tmp = fma(Float64(cos(eps) + -1.0), cos(x), Float64(sin(eps) * Float64(-sin(x)))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -3.8e-5], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.8e-5], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.8 \cdot 10^{-5}:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \cos x\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{elif}\;\varepsilon \leq 2.8 \cdot 10^{-5}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos \varepsilon + -1, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\end{array}
\end{array}
if eps < -3.8000000000000002e-5Initial program 42.1%
sub-neg42.1%
+-commutative42.1%
cos-sum98.3%
cancel-sign-sub-inv98.3%
associate-+r+98.5%
*-commutative98.5%
Applied egg-rr98.5%
+-commutative98.5%
unsub-neg98.5%
Applied egg-rr98.5%
if -3.8000000000000002e-5 < eps < 2.79999999999999996e-5Initial program 20.6%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
if 2.79999999999999996e-5 < eps Initial program 57.1%
sub-neg57.1%
cos-sum98.7%
cancel-sign-sub-inv98.7%
associate-+l+98.7%
*-commutative98.7%
Applied egg-rr98.7%
+-commutative98.7%
distribute-rgt-neg-out98.7%
*-commutative98.7%
unsub-neg98.7%
associate-+r-98.8%
*-commutative98.8%
neg-mul-198.8%
distribute-rgt-out98.8%
*-commutative98.8%
Simplified98.8%
*-commutative98.8%
fma-neg98.8%
distribute-rgt-neg-in98.8%
Applied egg-rr98.8%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.4e-5) (not (<= eps 3e-5))) (- (* (cos x) (+ (cos eps) -1.0)) (* (sin eps) (sin x))) (- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.4e-5) || !(eps <= 3e-5)) {
tmp = (cos(x) * (cos(eps) + -1.0)) - (sin(eps) * sin(x));
} else {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (eps * sin(x));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-4.4d-5)) .or. (.not. (eps <= 3d-5))) then
tmp = (cos(x) * (cos(eps) + (-1.0d0))) - (sin(eps) * sin(x))
else
tmp = (cos(x) * ((-0.5d0) * (eps ** 2.0d0))) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -4.4e-5) || !(eps <= 3e-5)) {
tmp = (Math.cos(x) * (Math.cos(eps) + -1.0)) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = (Math.cos(x) * (-0.5 * Math.pow(eps, 2.0))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4.4e-5) or not (eps <= 3e-5): tmp = (math.cos(x) * (math.cos(eps) + -1.0)) - (math.sin(eps) * math.sin(x)) else: tmp = (math.cos(x) * (-0.5 * math.pow(eps, 2.0))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -4.4e-5) || !(eps <= 3e-5)) tmp = Float64(Float64(cos(x) * Float64(cos(eps) + -1.0)) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -4.4e-5) || ~((eps <= 3e-5))) tmp = (cos(x) * (cos(eps) + -1.0)) - (sin(eps) * sin(x)); else tmp = (cos(x) * (-0.5 * (eps ^ 2.0))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.4e-5], N[Not[LessEqual[eps, 3e-5]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.4 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 3 \cdot 10^{-5}\right):\\
\;\;\;\;\cos x \cdot \left(\cos \varepsilon + -1\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -4.3999999999999999e-5 or 3.00000000000000008e-5 < eps Initial program 50.7%
sub-neg50.7%
cos-sum98.5%
cancel-sign-sub-inv98.5%
associate-+l+98.6%
*-commutative98.6%
Applied egg-rr98.6%
+-commutative98.6%
distribute-rgt-neg-out98.6%
*-commutative98.6%
unsub-neg98.6%
associate-+r-98.7%
*-commutative98.7%
neg-mul-198.7%
distribute-rgt-out98.6%
*-commutative98.6%
Simplified98.6%
if -4.3999999999999999e-5 < eps < 3.00000000000000008e-5Initial program 20.6%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- (cos (+ eps x)) (cos x)))) (if (<= t_0 -1e-12) t_0 (- (* eps (sin x))))))
double code(double x, double eps) {
double t_0 = cos((eps + x)) - cos(x);
double tmp;
if (t_0 <= -1e-12) {
tmp = t_0;
} else {
tmp = -(eps * sin(x));
}
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((eps + x)) - cos(x)
if (t_0 <= (-1d-12)) then
tmp = t_0
else
tmp = -(eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos((eps + x)) - Math.cos(x);
double tmp;
if (t_0 <= -1e-12) {
tmp = t_0;
} else {
tmp = -(eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): t_0 = math.cos((eps + x)) - math.cos(x) tmp = 0 if t_0 <= -1e-12: tmp = t_0 else: tmp = -(eps * math.sin(x)) return tmp
function code(x, eps) t_0 = Float64(cos(Float64(eps + x)) - cos(x)) tmp = 0.0 if (t_0 <= -1e-12) tmp = t_0; else tmp = Float64(-Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos((eps + x)) - cos(x); tmp = 0.0; if (t_0 <= -1e-12) tmp = t_0; else tmp = -(eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e-12], t$95$0, (-N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\varepsilon + x\right) - \cos x\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{-12}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-\varepsilon \cdot \sin x\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.9999999999999998e-13Initial program 75.0%
if -9.9999999999999998e-13 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 16.8%
Taylor expanded in eps around 0 62.4%
associate-*r*62.4%
mul-1-neg62.4%
Simplified62.4%
Final simplification66.4%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- (cos (+ eps x)) (cos x)))) (if (<= t_0 -1e-12) t_0 (* (sin eps) (- (sin x))))))
double code(double x, double eps) {
double t_0 = cos((eps + x)) - cos(x);
double tmp;
if (t_0 <= -1e-12) {
tmp = t_0;
} else {
tmp = sin(eps) * -sin(x);
}
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((eps + x)) - cos(x)
if (t_0 <= (-1d-12)) then
tmp = t_0
else
tmp = sin(eps) * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos((eps + x)) - Math.cos(x);
double tmp;
if (t_0 <= -1e-12) {
tmp = t_0;
} else {
tmp = Math.sin(eps) * -Math.sin(x);
}
return tmp;
}
def code(x, eps): t_0 = math.cos((eps + x)) - math.cos(x) tmp = 0 if t_0 <= -1e-12: tmp = t_0 else: tmp = math.sin(eps) * -math.sin(x) return tmp
function code(x, eps) t_0 = Float64(cos(Float64(eps + x)) - cos(x)) tmp = 0.0 if (t_0 <= -1e-12) tmp = t_0; else tmp = Float64(sin(eps) * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos((eps + x)) - cos(x); tmp = 0.0; if (t_0 <= -1e-12) tmp = t_0; else tmp = sin(eps) * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e-12], t$95$0, N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\varepsilon + x\right) - \cos x\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{-12}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sin \varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.9999999999999998e-13Initial program 75.0%
if -9.9999999999999998e-13 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 16.8%
sub-neg16.8%
+-commutative16.8%
cos-sum41.4%
cancel-sign-sub-inv41.4%
associate-+r+87.6%
*-commutative87.6%
Applied egg-rr87.6%
Taylor expanded in x around 0 64.6%
Taylor expanded in eps around 0 65.7%
Final simplification68.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.027) (not (<= eps 0.0038))) (- (cos eps) (cos x)) (- (* -0.5 (pow eps 2.0)) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.027) || !(eps <= 0.0038)) {
tmp = cos(eps) - cos(x);
} else {
tmp = (-0.5 * pow(eps, 2.0)) - (eps * sin(x));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.027d0)) .or. (.not. (eps <= 0.0038d0))) then
tmp = cos(eps) - cos(x)
else
tmp = ((-0.5d0) * (eps ** 2.0d0)) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.027) || !(eps <= 0.0038)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = (-0.5 * Math.pow(eps, 2.0)) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.027) or not (eps <= 0.0038): tmp = math.cos(eps) - math.cos(x) else: tmp = (-0.5 * math.pow(eps, 2.0)) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.027) || !(eps <= 0.0038)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(Float64(-0.5 * (eps ^ 2.0)) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.027) || ~((eps <= 0.0038))) tmp = cos(eps) - cos(x); else tmp = (-0.5 * (eps ^ 2.0)) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.027], N[Not[LessEqual[eps, 0.0038]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.027 \lor \neg \left(\varepsilon \leq 0.0038\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2} - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -0.0269999999999999997 or 0.00379999999999999999 < eps Initial program 50.7%
Taylor expanded in x around 0 52.5%
if -0.0269999999999999997 < eps < 0.00379999999999999999Initial program 20.6%
sub-neg20.6%
+-commutative20.6%
cos-sum21.0%
cancel-sign-sub-inv21.0%
associate-+r+83.3%
*-commutative83.3%
Applied egg-rr83.3%
Taylor expanded in x around 0 83.3%
Taylor expanded in eps around 0 99.5%
Final simplification76.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -5.4e-6) (not (<= eps 5.8e-6))) (- (cos eps) (cos x)) (- (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -5.4e-6) || !(eps <= 5.8e-6)) {
tmp = cos(eps) - cos(x);
} else {
tmp = -(eps * sin(x));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-5.4d-6)) .or. (.not. (eps <= 5.8d-6))) then
tmp = cos(eps) - cos(x)
else
tmp = -(eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -5.4e-6) || !(eps <= 5.8e-6)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = -(eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -5.4e-6) or not (eps <= 5.8e-6): tmp = math.cos(eps) - math.cos(x) else: tmp = -(eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -5.4e-6) || !(eps <= 5.8e-6)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(-Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -5.4e-6) || ~((eps <= 5.8e-6))) tmp = cos(eps) - cos(x); else tmp = -(eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -5.4e-6], N[Not[LessEqual[eps, 5.8e-6]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], (-N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5.4 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 5.8 \cdot 10^{-6}\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-\varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -5.39999999999999997e-6 or 5.8000000000000004e-6 < eps Initial program 50.7%
Taylor expanded in x around 0 52.5%
if -5.39999999999999997e-6 < eps < 5.8000000000000004e-6Initial program 20.6%
Taylor expanded in eps around 0 83.2%
associate-*r*83.2%
mul-1-neg83.2%
Simplified83.2%
Final simplification67.8%
(FPCore (x eps) :precision binary64 (* (sin (* 0.5 (+ eps (* x 2.0)))) (* -2.0 (sin (* eps 0.5)))))
double code(double x, double eps) {
return sin((0.5 * (eps + (x * 2.0)))) * (-2.0 * sin((eps * 0.5)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin((0.5d0 * (eps + (x * 2.0d0)))) * ((-2.0d0) * sin((eps * 0.5d0)))
end function
public static double code(double x, double eps) {
return Math.sin((0.5 * (eps + (x * 2.0)))) * (-2.0 * Math.sin((eps * 0.5)));
}
def code(x, eps): return math.sin((0.5 * (eps + (x * 2.0)))) * (-2.0 * math.sin((eps * 0.5)))
function code(x, eps) return Float64(sin(Float64(0.5 * Float64(eps + Float64(x * 2.0)))) * Float64(-2.0 * sin(Float64(eps * 0.5)))) end
function tmp = code(x, eps) tmp = sin((0.5 * (eps + (x * 2.0)))) * (-2.0 * sin((eps * 0.5))); end
code[x_, eps_] := N[(N[Sin[N[(0.5 * N[(eps + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(0.5 \cdot \left(\varepsilon + x \cdot 2\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 35.7%
diff-cos43.7%
div-inv43.7%
+-commutative43.7%
associate--l+75.8%
*-un-lft-identity75.8%
*-un-lft-identity75.8%
distribute-rgt-out--75.8%
metadata-eval75.8%
metadata-eval75.8%
div-inv75.8%
+-commutative75.8%
associate-+l+75.8%
count-275.8%
*-commutative75.8%
metadata-eval75.8%
Applied egg-rr75.8%
associate-*r*75.8%
*-commutative75.8%
*-commutative75.8%
*-commutative75.8%
mul0-rgt75.8%
Simplified75.8%
Final simplification75.8%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000125) (not (<= eps 0.00014))) (+ (cos eps) -1.0) (* -0.5 (pow eps 2.0))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000125) || !(eps <= 0.00014)) {
tmp = cos(eps) + -1.0;
} 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.000125d0)) .or. (.not. (eps <= 0.00014d0))) then
tmp = cos(eps) + (-1.0d0)
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.000125) || !(eps <= 0.00014)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = -0.5 * Math.pow(eps, 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000125) or not (eps <= 0.00014): tmp = math.cos(eps) + -1.0 else: tmp = -0.5 * math.pow(eps, 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000125) || !(eps <= 0.00014)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(-0.5 * (eps ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000125) || ~((eps <= 0.00014))) tmp = cos(eps) + -1.0; else tmp = -0.5 * (eps ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000125], N[Not[LessEqual[eps, 0.00014]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000125 \lor \neg \left(\varepsilon \leq 0.00014\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\end{array}
\end{array}
if eps < -1.25e-4 or 1.3999999999999999e-4 < eps Initial program 50.7%
Taylor expanded in x around 0 51.0%
if -1.25e-4 < eps < 1.3999999999999999e-4Initial program 20.6%
Taylor expanded in x around 0 20.5%
Taylor expanded in eps around 0 34.4%
Final simplification42.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.1e-5) (not (<= eps 2.7e-6))) (+ (cos eps) -1.0) (- (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.1e-5) || !(eps <= 2.7e-6)) {
tmp = cos(eps) + -1.0;
} else {
tmp = -(eps * sin(x));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.1d-5)) .or. (.not. (eps <= 2.7d-6))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = -(eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.1e-5) || !(eps <= 2.7e-6)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = -(eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.1e-5) or not (eps <= 2.7e-6): tmp = math.cos(eps) + -1.0 else: tmp = -(eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.1e-5) || !(eps <= 2.7e-6)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(-Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.1e-5) || ~((eps <= 2.7e-6))) tmp = cos(eps) + -1.0; else tmp = -(eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.1e-5], N[Not[LessEqual[eps, 2.7e-6]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], (-N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.1 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 2.7 \cdot 10^{-6}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;-\varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -1.1e-5 or 2.69999999999999998e-6 < eps Initial program 50.7%
Taylor expanded in x around 0 51.0%
if -1.1e-5 < eps < 2.69999999999999998e-6Initial program 20.6%
Taylor expanded in eps around 0 83.2%
associate-*r*83.2%
mul-1-neg83.2%
Simplified83.2%
Final simplification67.1%
(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 35.7%
Taylor expanded in x around 0 35.7%
add-log-exp35.7%
Applied egg-rr35.7%
add-log-exp35.7%
flip--35.7%
metadata-eval35.7%
sub-1-cos42.8%
unpow242.7%
neg-mul-142.7%
*-un-lft-identity42.7%
times-frac42.7%
metadata-eval42.7%
add-sqr-sqrt42.8%
sqrt-unprod39.4%
sqr-neg39.4%
sqrt-unprod8.6%
add-sqr-sqrt13.3%
unpow213.3%
sub-1-cos13.4%
metadata-eval13.4%
flip--13.4%
sub-neg13.4%
metadata-eval13.4%
Applied egg-rr13.4%
+-commutative13.4%
distribute-lft-in13.4%
metadata-eval13.4%
neg-mul-113.4%
sub-neg13.4%
Simplified13.4%
Final simplification13.4%
(FPCore (x eps) :precision binary64 (+ (cos eps) -1.0))
double code(double x, double eps) {
return cos(eps) + -1.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos(eps) + (-1.0d0)
end function
public static double code(double x, double eps) {
return Math.cos(eps) + -1.0;
}
def code(x, eps): return math.cos(eps) + -1.0
function code(x, eps) return Float64(cos(eps) + -1.0) end
function tmp = code(x, eps) tmp = cos(eps) + -1.0; end
code[x_, eps_] := N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\cos \varepsilon + -1
\end{array}
Initial program 35.7%
Taylor expanded in x around 0 35.7%
Final simplification35.7%
(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 35.7%
diff-cos43.7%
sin-mult35.5%
associate-*r/35.5%
Applied egg-rr35.7%
*-commutative35.7%
associate-/l*35.7%
associate--l+35.7%
mul0-rgt35.7%
mul0-rgt35.7%
metadata-eval35.7%
Simplified35.7%
sub-neg35.7%
Applied egg-rr11.7%
sub-neg11.7%
+-inverses11.7%
Simplified11.7%
Final simplification11.7%
herbie shell --seed 2023336
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))