
(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
(if (<= eps -0.0027)
(- (fma (cos x) (cos eps) (* (sin x) (- (sin eps)))) (cos x))
(if (<= eps 0.0031)
(-
(+
(* 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)))
(- (- (* (cos x) (cos eps)) (* (sin x) (sin eps))) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0027) {
tmp = fma(cos(x), cos(eps), (sin(x) * -sin(eps))) - cos(x);
} else if (eps <= 0.0031) {
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 = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.0027) tmp = Float64(fma(cos(x), cos(eps), Float64(sin(x) * Float64(-sin(eps)))) - cos(x)); elseif (eps <= 0.0031) 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(Float64(Float64(cos(x) * cos(eps)) - Float64(sin(x) * sin(eps))) - cos(x)); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.0027], 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], If[LessEqual[eps, 0.0031], 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[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $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.0027:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin x \cdot \left(-\sin \varepsilon\right)\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 0.0031:\\
\;\;\;\;\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}:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \sin x \cdot \sin \varepsilon\right) - \cos x\\
\end{array}
\end{array}
if eps < -0.0027000000000000001Initial program 45.4%
cos-sum98.3%
cancel-sign-sub-inv98.3%
fma-def98.4%
Applied egg-rr98.4%
if -0.0027000000000000001 < eps < 0.00309999999999999989Initial program 23.1%
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.00309999999999999989 < eps Initial program 55.5%
cos-sum99.2%
Applied egg-rr99.2%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.0024)
(- (fma (cos x) (cos eps) (* (sin x) (- (sin eps)))) (cos x))
(if (<= eps 0.0023)
(+
(*
(cos x)
(+ (* -0.5 (pow eps 2.0)) (* 0.041666666666666664 (pow eps 4.0))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))
(- (- (* (cos x) (cos eps)) (* (sin x) (sin eps))) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0024) {
tmp = fma(cos(x), cos(eps), (sin(x) * -sin(eps))) - cos(x);
} else if (eps <= 0.0023) {
tmp = (cos(x) * ((-0.5 * pow(eps, 2.0)) + (0.041666666666666664 * pow(eps, 4.0)))) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - eps));
} else {
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.0024) tmp = Float64(fma(cos(x), cos(eps), Float64(sin(x) * Float64(-sin(eps)))) - cos(x)); elseif (eps <= 0.0023) tmp = Float64(Float64(cos(x) * Float64(Float64(-0.5 * (eps ^ 2.0)) + Float64(0.041666666666666664 * (eps ^ 4.0)))) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps))); else tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - Float64(sin(x) * sin(eps))) - cos(x)); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.0024], 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], If[LessEqual[eps, 0.0023], N[(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] + N[(N[Sin[x], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $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.0024:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin x \cdot \left(-\sin \varepsilon\right)\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 0.0023:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2} + 0.041666666666666664 \cdot {\varepsilon}^{4}\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \sin x \cdot \sin \varepsilon\right) - \cos x\\
\end{array}
\end{array}
if eps < -0.00239999999999999979Initial program 45.4%
cos-sum98.3%
cancel-sign-sub-inv98.3%
fma-def98.4%
Applied egg-rr98.4%
if -0.00239999999999999979 < eps < 0.0023Initial program 23.1%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
associate-+r+99.8%
associate-+l+99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
mul-1-neg99.8%
Simplified99.8%
if 0.0023 < eps Initial program 55.5%
cos-sum99.2%
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (cos x) (cos eps))) (t_1 (* (sin x) (sin eps))))
(if (<= eps -0.00019)
(- t_0 (+ (cos x) t_1))
(if (<= eps 0.00018)
(*
(+
(sin x)
(+ (* -0.125 (* (sin x) (pow eps 2.0))) (* 0.5 (* eps (cos x)))))
(* -2.0 (sin (* eps 0.5))))
(- (- t_0 t_1) (cos x))))))
double code(double x, double eps) {
double t_0 = cos(x) * cos(eps);
double t_1 = sin(x) * sin(eps);
double tmp;
if (eps <= -0.00019) {
tmp = t_0 - (cos(x) + t_1);
} else if (eps <= 0.00018) {
tmp = (sin(x) + ((-0.125 * (sin(x) * pow(eps, 2.0))) + (0.5 * (eps * cos(x))))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = (t_0 - t_1) - cos(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) :: t_1
real(8) :: tmp
t_0 = cos(x) * cos(eps)
t_1 = sin(x) * sin(eps)
if (eps <= (-0.00019d0)) then
tmp = t_0 - (cos(x) + t_1)
else if (eps <= 0.00018d0) then
tmp = (sin(x) + (((-0.125d0) * (sin(x) * (eps ** 2.0d0))) + (0.5d0 * (eps * cos(x))))) * ((-2.0d0) * sin((eps * 0.5d0)))
else
tmp = (t_0 - t_1) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(x) * Math.cos(eps);
double t_1 = Math.sin(x) * Math.sin(eps);
double tmp;
if (eps <= -0.00019) {
tmp = t_0 - (Math.cos(x) + t_1);
} else if (eps <= 0.00018) {
tmp = (Math.sin(x) + ((-0.125 * (Math.sin(x) * Math.pow(eps, 2.0))) + (0.5 * (eps * Math.cos(x))))) * (-2.0 * Math.sin((eps * 0.5)));
} else {
tmp = (t_0 - t_1) - Math.cos(x);
}
return tmp;
}
def code(x, eps): t_0 = math.cos(x) * math.cos(eps) t_1 = math.sin(x) * math.sin(eps) tmp = 0 if eps <= -0.00019: tmp = t_0 - (math.cos(x) + t_1) elif eps <= 0.00018: tmp = (math.sin(x) + ((-0.125 * (math.sin(x) * math.pow(eps, 2.0))) + (0.5 * (eps * math.cos(x))))) * (-2.0 * math.sin((eps * 0.5))) else: tmp = (t_0 - t_1) - math.cos(x) return tmp
function code(x, eps) t_0 = Float64(cos(x) * cos(eps)) t_1 = Float64(sin(x) * sin(eps)) tmp = 0.0 if (eps <= -0.00019) tmp = Float64(t_0 - Float64(cos(x) + t_1)); elseif (eps <= 0.00018) tmp = Float64(Float64(sin(x) + Float64(Float64(-0.125 * Float64(sin(x) * (eps ^ 2.0))) + Float64(0.5 * Float64(eps * cos(x))))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = Float64(Float64(t_0 - t_1) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(x) * cos(eps); t_1 = sin(x) * sin(eps); tmp = 0.0; if (eps <= -0.00019) tmp = t_0 - (cos(x) + t_1); elseif (eps <= 0.00018) tmp = (sin(x) + ((-0.125 * (sin(x) * (eps ^ 2.0))) + (0.5 * (eps * cos(x))))) * (-2.0 * sin((eps * 0.5))); else tmp = (t_0 - t_1) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00019], N[(t$95$0 - N[(N[Cos[x], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00018], N[(N[(N[Sin[x], $MachinePrecision] + N[(N[(-0.125 * N[(N[Sin[x], $MachinePrecision] * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - t$95$1), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \cos \varepsilon\\
t_1 := \sin x \cdot \sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.00019:\\
\;\;\;\;t_0 - \left(\cos x + t_1\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00018:\\
\;\;\;\;\left(\sin x + \left(-0.125 \cdot \left(\sin x \cdot {\varepsilon}^{2}\right) + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t_0 - t_1\right) - \cos x\\
\end{array}
\end{array}
if eps < -1.9000000000000001e-4Initial program 44.8%
add-log-exp44.7%
Applied egg-rr44.7%
rem-log-exp44.8%
cos-sum98.1%
associate--l-98.2%
*-commutative98.2%
Applied egg-rr98.2%
if -1.9000000000000001e-4 < eps < 1.80000000000000011e-4Initial program 23.3%
diff-cos40.6%
div-inv40.6%
associate--l+40.6%
metadata-eval40.6%
div-inv40.6%
+-commutative40.6%
associate-+l+40.6%
metadata-eval40.6%
Applied egg-rr40.6%
associate-*r*40.6%
*-commutative40.6%
*-commutative40.6%
+-commutative40.6%
count-240.6%
fma-def40.6%
sub-neg40.6%
mul-1-neg40.6%
+-commutative40.6%
associate-+r+99.0%
mul-1-neg99.0%
sub-neg99.0%
+-inverses99.0%
remove-double-neg99.0%
mul-1-neg99.0%
sub-neg99.0%
neg-sub099.0%
mul-1-neg99.0%
remove-double-neg99.0%
Simplified99.0%
Taylor expanded in eps around 0 99.7%
if 1.80000000000000011e-4 < eps Initial program 55.5%
cos-sum99.2%
Applied egg-rr99.2%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (cos x) (cos eps))) (t_1 (* (sin x) (sin eps))))
(if (<= eps -0.0028)
(- t_0 (+ (cos x) t_1))
(if (<= eps 0.0023)
(+
(*
(cos x)
(+ (* -0.5 (pow eps 2.0)) (* 0.041666666666666664 (pow eps 4.0))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))
(- (- t_0 t_1) (cos x))))))
double code(double x, double eps) {
double t_0 = cos(x) * cos(eps);
double t_1 = sin(x) * sin(eps);
double tmp;
if (eps <= -0.0028) {
tmp = t_0 - (cos(x) + t_1);
} else if (eps <= 0.0023) {
tmp = (cos(x) * ((-0.5 * pow(eps, 2.0)) + (0.041666666666666664 * pow(eps, 4.0)))) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - eps));
} else {
tmp = (t_0 - t_1) - cos(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) :: t_1
real(8) :: tmp
t_0 = cos(x) * cos(eps)
t_1 = sin(x) * sin(eps)
if (eps <= (-0.0028d0)) then
tmp = t_0 - (cos(x) + t_1)
else if (eps <= 0.0023d0) then
tmp = (cos(x) * (((-0.5d0) * (eps ** 2.0d0)) + (0.041666666666666664d0 * (eps ** 4.0d0)))) + (sin(x) * ((0.16666666666666666d0 * (eps ** 3.0d0)) - eps))
else
tmp = (t_0 - t_1) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(x) * Math.cos(eps);
double t_1 = Math.sin(x) * Math.sin(eps);
double tmp;
if (eps <= -0.0028) {
tmp = t_0 - (Math.cos(x) + t_1);
} else if (eps <= 0.0023) {
tmp = (Math.cos(x) * ((-0.5 * Math.pow(eps, 2.0)) + (0.041666666666666664 * Math.pow(eps, 4.0)))) + (Math.sin(x) * ((0.16666666666666666 * Math.pow(eps, 3.0)) - eps));
} else {
tmp = (t_0 - t_1) - Math.cos(x);
}
return tmp;
}
def code(x, eps): t_0 = math.cos(x) * math.cos(eps) t_1 = math.sin(x) * math.sin(eps) tmp = 0 if eps <= -0.0028: tmp = t_0 - (math.cos(x) + t_1) elif eps <= 0.0023: tmp = (math.cos(x) * ((-0.5 * math.pow(eps, 2.0)) + (0.041666666666666664 * math.pow(eps, 4.0)))) + (math.sin(x) * ((0.16666666666666666 * math.pow(eps, 3.0)) - eps)) else: tmp = (t_0 - t_1) - math.cos(x) return tmp
function code(x, eps) t_0 = Float64(cos(x) * cos(eps)) t_1 = Float64(sin(x) * sin(eps)) tmp = 0.0 if (eps <= -0.0028) tmp = Float64(t_0 - Float64(cos(x) + t_1)); elseif (eps <= 0.0023) tmp = Float64(Float64(cos(x) * Float64(Float64(-0.5 * (eps ^ 2.0)) + Float64(0.041666666666666664 * (eps ^ 4.0)))) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps))); else tmp = Float64(Float64(t_0 - t_1) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(x) * cos(eps); t_1 = sin(x) * sin(eps); tmp = 0.0; if (eps <= -0.0028) tmp = t_0 - (cos(x) + t_1); elseif (eps <= 0.0023) tmp = (cos(x) * ((-0.5 * (eps ^ 2.0)) + (0.041666666666666664 * (eps ^ 4.0)))) + (sin(x) * ((0.16666666666666666 * (eps ^ 3.0)) - eps)); else tmp = (t_0 - t_1) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.0028], N[(t$95$0 - N[(N[Cos[x], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.0023], N[(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] + N[(N[Sin[x], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - t$95$1), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \cos \varepsilon\\
t_1 := \sin x \cdot \sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.0028:\\
\;\;\;\;t_0 - \left(\cos x + t_1\right)\\
\mathbf{elif}\;\varepsilon \leq 0.0023:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2} + 0.041666666666666664 \cdot {\varepsilon}^{4}\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t_0 - t_1\right) - \cos x\\
\end{array}
\end{array}
if eps < -0.00279999999999999997Initial program 45.4%
add-log-exp45.3%
Applied egg-rr45.3%
rem-log-exp45.4%
cos-sum98.3%
associate--l-98.4%
*-commutative98.4%
Applied egg-rr98.4%
if -0.00279999999999999997 < eps < 0.0023Initial program 23.1%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
associate-+r+99.8%
associate-+l+99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
mul-1-neg99.8%
Simplified99.8%
if 0.0023 < eps Initial program 55.5%
cos-sum99.2%
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00019) (not (<= eps 0.00018)))
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps))))
(*
(* -2.0 (sin (* eps 0.5)))
(+ (* (sin x) (+ (* (pow eps 2.0) -0.125) 1.0)) (* (cos x) (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00019) || !(eps <= 0.00018)) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
} else {
tmp = (-2.0 * sin((eps * 0.5))) * ((sin(x) * ((pow(eps, 2.0) * -0.125) + 1.0)) + (cos(x) * (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 <= (-0.00019d0)) .or. (.not. (eps <= 0.00018d0))) then
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)))
else
tmp = ((-2.0d0) * sin((eps * 0.5d0))) * ((sin(x) * (((eps ** 2.0d0) * (-0.125d0)) + 1.0d0)) + (cos(x) * (eps * 0.5d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.00019) || !(eps <= 0.00018)) {
tmp = (Math.cos(x) * Math.cos(eps)) - (Math.cos(x) + (Math.sin(x) * Math.sin(eps)));
} else {
tmp = (-2.0 * Math.sin((eps * 0.5))) * ((Math.sin(x) * ((Math.pow(eps, 2.0) * -0.125) + 1.0)) + (Math.cos(x) * (eps * 0.5)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00019) or not (eps <= 0.00018): tmp = (math.cos(x) * math.cos(eps)) - (math.cos(x) + (math.sin(x) * math.sin(eps))) else: tmp = (-2.0 * math.sin((eps * 0.5))) * ((math.sin(x) * ((math.pow(eps, 2.0) * -0.125) + 1.0)) + (math.cos(x) * (eps * 0.5))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00019) || !(eps <= 0.00018)) tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(x) * sin(eps)))); else tmp = Float64(Float64(-2.0 * sin(Float64(eps * 0.5))) * Float64(Float64(sin(x) * Float64(Float64((eps ^ 2.0) * -0.125) + 1.0)) + Float64(cos(x) * Float64(eps * 0.5)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00019) || ~((eps <= 0.00018))) tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps))); else tmp = (-2.0 * sin((eps * 0.5))) * ((sin(x) * (((eps ^ 2.0) * -0.125) + 1.0)) + (cos(x) * (eps * 0.5))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00019], N[Not[LessEqual[eps, 0.00018]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(N[Power[eps, 2.0], $MachinePrecision] * -0.125), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(eps * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00019 \lor \neg \left(\varepsilon \leq 0.00018\right):\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(\sin x \cdot \left({\varepsilon}^{2} \cdot -0.125 + 1\right) + \cos x \cdot \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -1.9000000000000001e-4 or 1.80000000000000011e-4 < eps Initial program 49.5%
add-log-exp49.3%
Applied egg-rr49.3%
rem-log-exp49.5%
cos-sum98.6%
associate--l-98.6%
*-commutative98.6%
Applied egg-rr98.6%
if -1.9000000000000001e-4 < eps < 1.80000000000000011e-4Initial program 23.3%
diff-cos40.6%
div-inv40.6%
associate--l+40.6%
metadata-eval40.6%
div-inv40.6%
+-commutative40.6%
associate-+l+40.6%
metadata-eval40.6%
Applied egg-rr40.6%
associate-*r*40.6%
*-commutative40.6%
*-commutative40.6%
+-commutative40.6%
count-240.6%
fma-def40.6%
sub-neg40.6%
mul-1-neg40.6%
+-commutative40.6%
associate-+r+99.0%
mul-1-neg99.0%
sub-neg99.0%
+-inverses99.0%
remove-double-neg99.0%
mul-1-neg99.0%
sub-neg99.0%
neg-sub099.0%
mul-1-neg99.0%
remove-double-neg99.0%
Simplified99.0%
Taylor expanded in eps around 0 99.7%
associate-+r+99.7%
associate-*r*99.7%
distribute-rgt1-in99.7%
associate-*r*99.7%
Simplified99.7%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (cos x) (cos eps))) (t_1 (* (sin x) (sin eps))))
(if (<= eps -0.00019)
(- t_0 (+ (cos x) t_1))
(if (<= eps 0.00017)
(*
(* -2.0 (sin (* eps 0.5)))
(+
(* (sin x) (+ (* (pow eps 2.0) -0.125) 1.0))
(* (cos x) (* eps 0.5))))
(- (- t_0 t_1) (cos x))))))
double code(double x, double eps) {
double t_0 = cos(x) * cos(eps);
double t_1 = sin(x) * sin(eps);
double tmp;
if (eps <= -0.00019) {
tmp = t_0 - (cos(x) + t_1);
} else if (eps <= 0.00017) {
tmp = (-2.0 * sin((eps * 0.5))) * ((sin(x) * ((pow(eps, 2.0) * -0.125) + 1.0)) + (cos(x) * (eps * 0.5)));
} else {
tmp = (t_0 - t_1) - cos(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) :: t_1
real(8) :: tmp
t_0 = cos(x) * cos(eps)
t_1 = sin(x) * sin(eps)
if (eps <= (-0.00019d0)) then
tmp = t_0 - (cos(x) + t_1)
else if (eps <= 0.00017d0) then
tmp = ((-2.0d0) * sin((eps * 0.5d0))) * ((sin(x) * (((eps ** 2.0d0) * (-0.125d0)) + 1.0d0)) + (cos(x) * (eps * 0.5d0)))
else
tmp = (t_0 - t_1) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(x) * Math.cos(eps);
double t_1 = Math.sin(x) * Math.sin(eps);
double tmp;
if (eps <= -0.00019) {
tmp = t_0 - (Math.cos(x) + t_1);
} else if (eps <= 0.00017) {
tmp = (-2.0 * Math.sin((eps * 0.5))) * ((Math.sin(x) * ((Math.pow(eps, 2.0) * -0.125) + 1.0)) + (Math.cos(x) * (eps * 0.5)));
} else {
tmp = (t_0 - t_1) - Math.cos(x);
}
return tmp;
}
def code(x, eps): t_0 = math.cos(x) * math.cos(eps) t_1 = math.sin(x) * math.sin(eps) tmp = 0 if eps <= -0.00019: tmp = t_0 - (math.cos(x) + t_1) elif eps <= 0.00017: tmp = (-2.0 * math.sin((eps * 0.5))) * ((math.sin(x) * ((math.pow(eps, 2.0) * -0.125) + 1.0)) + (math.cos(x) * (eps * 0.5))) else: tmp = (t_0 - t_1) - math.cos(x) return tmp
function code(x, eps) t_0 = Float64(cos(x) * cos(eps)) t_1 = Float64(sin(x) * sin(eps)) tmp = 0.0 if (eps <= -0.00019) tmp = Float64(t_0 - Float64(cos(x) + t_1)); elseif (eps <= 0.00017) tmp = Float64(Float64(-2.0 * sin(Float64(eps * 0.5))) * Float64(Float64(sin(x) * Float64(Float64((eps ^ 2.0) * -0.125) + 1.0)) + Float64(cos(x) * Float64(eps * 0.5)))); else tmp = Float64(Float64(t_0 - t_1) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(x) * cos(eps); t_1 = sin(x) * sin(eps); tmp = 0.0; if (eps <= -0.00019) tmp = t_0 - (cos(x) + t_1); elseif (eps <= 0.00017) tmp = (-2.0 * sin((eps * 0.5))) * ((sin(x) * (((eps ^ 2.0) * -0.125) + 1.0)) + (cos(x) * (eps * 0.5))); else tmp = (t_0 - t_1) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00019], N[(t$95$0 - N[(N[Cos[x], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00017], N[(N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(N[Power[eps, 2.0], $MachinePrecision] * -0.125), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(eps * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - t$95$1), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \cos \varepsilon\\
t_1 := \sin x \cdot \sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.00019:\\
\;\;\;\;t_0 - \left(\cos x + t_1\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00017:\\
\;\;\;\;\left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(\sin x \cdot \left({\varepsilon}^{2} \cdot -0.125 + 1\right) + \cos x \cdot \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t_0 - t_1\right) - \cos x\\
\end{array}
\end{array}
if eps < -1.9000000000000001e-4Initial program 44.8%
add-log-exp44.7%
Applied egg-rr44.7%
rem-log-exp44.8%
cos-sum98.1%
associate--l-98.2%
*-commutative98.2%
Applied egg-rr98.2%
if -1.9000000000000001e-4 < eps < 1.7e-4Initial program 23.3%
diff-cos40.6%
div-inv40.6%
associate--l+40.6%
metadata-eval40.6%
div-inv40.6%
+-commutative40.6%
associate-+l+40.6%
metadata-eval40.6%
Applied egg-rr40.6%
associate-*r*40.6%
*-commutative40.6%
*-commutative40.6%
+-commutative40.6%
count-240.6%
fma-def40.6%
sub-neg40.6%
mul-1-neg40.6%
+-commutative40.6%
associate-+r+99.0%
mul-1-neg99.0%
sub-neg99.0%
+-inverses99.0%
remove-double-neg99.0%
mul-1-neg99.0%
sub-neg99.0%
neg-sub099.0%
mul-1-neg99.0%
remove-double-neg99.0%
Simplified99.0%
Taylor expanded in eps around 0 99.7%
associate-+r+99.7%
associate-*r*99.7%
distribute-rgt1-in99.7%
associate-*r*99.7%
Simplified99.7%
if 1.7e-4 < eps Initial program 55.5%
cos-sum99.2%
Applied egg-rr99.2%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -0.0002) (* -2.0 (pow (sin (* eps 0.5)) 2.0)) (* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (* eps 0.5)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -0.0002) {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
} else {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * (eps * 0.5));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -0.0002) tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); else tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * Float64(eps * 0.5))); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -0.0002], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[(eps * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -0.0002:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right) \cdot \left(-2 \cdot \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -2.0000000000000001e-4Initial program 72.6%
diff-cos73.2%
div-inv73.2%
associate--l+73.2%
metadata-eval73.2%
div-inv73.2%
+-commutative73.2%
associate-+l+73.9%
metadata-eval73.9%
Applied egg-rr73.9%
associate-*r*73.9%
*-commutative73.9%
*-commutative73.9%
+-commutative73.9%
count-273.9%
fma-def73.9%
sub-neg73.9%
mul-1-neg73.9%
+-commutative73.9%
associate-+r+73.4%
mul-1-neg73.4%
sub-neg73.4%
+-inverses73.4%
remove-double-neg73.4%
mul-1-neg73.4%
sub-neg73.4%
neg-sub073.4%
mul-1-neg73.4%
remove-double-neg73.4%
Simplified73.4%
Taylor expanded in x around 0 72.6%
if -2.0000000000000001e-4 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 18.9%
diff-cos31.0%
div-inv31.0%
associate--l+31.0%
metadata-eval31.0%
div-inv31.0%
+-commutative31.0%
associate-+l+31.0%
metadata-eval31.0%
Applied egg-rr31.0%
associate-*r*31.0%
*-commutative31.0%
*-commutative31.0%
+-commutative31.0%
count-231.0%
fma-def31.0%
sub-neg31.0%
mul-1-neg31.0%
+-commutative31.0%
associate-+r+74.9%
mul-1-neg74.9%
sub-neg74.9%
+-inverses74.9%
remove-double-neg74.9%
mul-1-neg74.9%
sub-neg74.9%
neg-sub074.9%
mul-1-neg74.9%
remove-double-neg74.9%
Simplified74.9%
Taylor expanded in eps around 0 73.5%
Final simplification73.2%
(FPCore (x eps) :precision binary64 (* (* -2.0 (sin (* eps 0.5))) (sin (* 0.5 (fma 2.0 x eps)))))
double code(double x, double eps) {
return (-2.0 * sin((eps * 0.5))) * sin((0.5 * fma(2.0, x, eps)));
}
function code(x, eps) return Float64(Float64(-2.0 * sin(Float64(eps * 0.5))) * sin(Float64(0.5 * fma(2.0, x, eps)))) end
code[x_, eps_] := N[(N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right) \cdot \sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right)
\end{array}
Initial program 36.7%
diff-cos45.0%
div-inv45.0%
associate--l+45.0%
metadata-eval45.0%
div-inv45.0%
+-commutative45.0%
associate-+l+45.2%
metadata-eval45.2%
Applied egg-rr45.2%
associate-*r*45.2%
*-commutative45.2%
*-commutative45.2%
+-commutative45.2%
count-245.2%
fma-def45.2%
sub-neg45.2%
mul-1-neg45.2%
+-commutative45.2%
associate-+r+74.4%
mul-1-neg74.4%
sub-neg74.4%
+-inverses74.4%
remove-double-neg74.4%
mul-1-neg74.4%
sub-neg74.4%
neg-sub074.4%
mul-1-neg74.4%
remove-double-neg74.4%
Simplified74.4%
Final simplification74.4%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.00028)
(- (cos eps) (cos x))
(if (or (<= eps -3e-29) (and (not (<= eps -2.8e-77)) (<= eps 3.3e-71)))
(* eps (- (sin x)))
(* -2.0 (pow (sin (* eps 0.5)) 2.0)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.00028) {
tmp = cos(eps) - cos(x);
} else if ((eps <= -3e-29) || (!(eps <= -2.8e-77) && (eps <= 3.3e-71))) {
tmp = eps * -sin(x);
} else {
tmp = -2.0 * pow(sin((eps * 0.5)), 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.00028d0)) then
tmp = cos(eps) - cos(x)
else if ((eps <= (-3d-29)) .or. (.not. (eps <= (-2.8d-77))) .and. (eps <= 3.3d-71)) then
tmp = eps * -sin(x)
else
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -0.00028) {
tmp = Math.cos(eps) - Math.cos(x);
} else if ((eps <= -3e-29) || (!(eps <= -2.8e-77) && (eps <= 3.3e-71))) {
tmp = eps * -Math.sin(x);
} else {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.00028: tmp = math.cos(eps) - math.cos(x) elif (eps <= -3e-29) or (not (eps <= -2.8e-77) and (eps <= 3.3e-71)): tmp = eps * -math.sin(x) else: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.00028) tmp = Float64(cos(eps) - cos(x)); elseif ((eps <= -3e-29) || (!(eps <= -2.8e-77) && (eps <= 3.3e-71))) tmp = Float64(eps * Float64(-sin(x))); else tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -0.00028) tmp = cos(eps) - cos(x); elseif ((eps <= -3e-29) || (~((eps <= -2.8e-77)) && (eps <= 3.3e-71))) tmp = eps * -sin(x); else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.00028], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[eps, -3e-29], And[N[Not[LessEqual[eps, -2.8e-77]], $MachinePrecision], LessEqual[eps, 3.3e-71]]], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00028:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{elif}\;\varepsilon \leq -3 \cdot 10^{-29} \lor \neg \left(\varepsilon \leq -2.8 \cdot 10^{-77}\right) \land \varepsilon \leq 3.3 \cdot 10^{-71}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if eps < -2.7999999999999998e-4Initial program 45.4%
Taylor expanded in x around 0 46.8%
if -2.7999999999999998e-4 < eps < -3.0000000000000003e-29 or -2.7999999999999999e-77 < eps < 3.3000000000000002e-71Initial program 27.2%
Taylor expanded in eps around 0 93.1%
mul-1-neg93.1%
*-commutative93.1%
distribute-rgt-neg-in93.1%
Simplified93.1%
if -3.0000000000000003e-29 < eps < -2.7999999999999999e-77 or 3.3000000000000002e-71 < eps Initial program 41.1%
diff-cos60.7%
div-inv60.7%
associate--l+60.7%
metadata-eval60.7%
div-inv60.7%
+-commutative60.7%
associate-+l+61.1%
metadata-eval61.1%
Applied egg-rr61.1%
associate-*r*61.1%
*-commutative61.1%
*-commutative61.1%
+-commutative61.1%
count-261.1%
fma-def61.1%
sub-neg61.1%
mul-1-neg61.1%
+-commutative61.1%
associate-+r+68.5%
mul-1-neg68.5%
sub-neg68.5%
+-inverses68.5%
remove-double-neg68.5%
mul-1-neg68.5%
sub-neg68.5%
neg-sub068.5%
mul-1-neg68.5%
remove-double-neg68.5%
Simplified68.5%
Taylor expanded in x around 0 61.6%
Final simplification70.2%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* eps 0.5)) (sin (* 0.5 (- eps (* x -2.0)))))))
double code(double x, double eps) {
return -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps - (x * -2.0)))));
}
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 * (-2.0d0))))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((eps * 0.5)) * Math.sin((0.5 * (eps - (x * -2.0)))));
}
def code(x, eps): return -2.0 * (math.sin((eps * 0.5)) * math.sin((0.5 * (eps - (x * -2.0)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(eps * 0.5)) * sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps - (x * -2.0))))); 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 * -2.0), $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 - x \cdot -2\right)\right)\right)
\end{array}
Initial program 36.7%
add-log-exp36.6%
Applied egg-rr36.6%
rem-log-exp36.7%
diff-cos45.0%
*-commutative45.0%
div-inv45.0%
+-commutative45.0%
associate--l+74.2%
metadata-eval74.2%
div-inv74.2%
+-commutative74.2%
metadata-eval74.2%
Applied egg-rr74.2%
Taylor expanded in x around -inf 74.3%
Final simplification74.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -300000.0) (not (<= x 31500.0)))
(* (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 <= -300000.0) || !(x <= 31500.0)) {
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 <= (-300000.0d0)) .or. (.not. (x <= 31500.0d0))) 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 <= -300000.0) || !(x <= 31500.0)) {
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 <= -300000.0) or not (x <= 31500.0): 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 <= -300000.0) || !(x <= 31500.0)) 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 <= -300000.0) || ~((x <= 31500.0))) 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, -300000.0], N[Not[LessEqual[x, 31500.0]], $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 -300000 \lor \neg \left(x \leq 31500\right):\\
\;\;\;\;\sin x \cdot \left(-2 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -3e5 or 31500 < x Initial program 7.2%
diff-cos6.6%
div-inv6.6%
associate--l+6.6%
metadata-eval6.6%
div-inv6.6%
+-commutative6.6%
associate-+l+6.9%
metadata-eval6.9%
Applied egg-rr6.9%
associate-*r*6.9%
*-commutative6.9%
*-commutative6.9%
+-commutative6.9%
count-26.9%
fma-def6.9%
sub-neg6.9%
mul-1-neg6.9%
+-commutative6.9%
associate-+r+52.7%
mul-1-neg52.7%
sub-neg52.7%
+-inverses52.7%
remove-double-neg52.7%
mul-1-neg52.7%
sub-neg52.7%
neg-sub052.7%
mul-1-neg52.7%
remove-double-neg52.7%
Simplified52.7%
Taylor expanded in eps around 0 53.3%
if -3e5 < x < 31500Initial program 69.0%
diff-cos87.1%
div-inv87.1%
associate--l+87.1%
metadata-eval87.1%
div-inv87.1%
+-commutative87.1%
associate-+l+87.4%
metadata-eval87.4%
Applied egg-rr87.4%
associate-*r*87.4%
*-commutative87.4%
*-commutative87.4%
+-commutative87.4%
count-287.4%
fma-def87.4%
sub-neg87.4%
mul-1-neg87.4%
+-commutative87.4%
associate-+r+98.2%
mul-1-neg98.2%
sub-neg98.2%
+-inverses98.2%
remove-double-neg98.2%
mul-1-neg98.2%
sub-neg98.2%
neg-sub098.2%
mul-1-neg98.2%
remove-double-neg98.2%
Simplified98.2%
Taylor expanded in x around 0 85.9%
Final simplification68.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (cos eps) (cos x))))
(if (<= eps -0.00028)
t_0
(if (<= eps 3.3e-71)
(* eps (- (sin x)))
(if (<= eps 1.65) (* -0.5 (pow eps 2.0)) t_0)))))
double code(double x, double eps) {
double t_0 = cos(eps) - cos(x);
double tmp;
if (eps <= -0.00028) {
tmp = t_0;
} else if (eps <= 3.3e-71) {
tmp = eps * -sin(x);
} else if (eps <= 1.65) {
tmp = -0.5 * pow(eps, 2.0);
} else {
tmp = t_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(eps) - cos(x)
if (eps <= (-0.00028d0)) then
tmp = t_0
else if (eps <= 3.3d-71) then
tmp = eps * -sin(x)
else if (eps <= 1.65d0) then
tmp = (-0.5d0) * (eps ** 2.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(eps) - Math.cos(x);
double tmp;
if (eps <= -0.00028) {
tmp = t_0;
} else if (eps <= 3.3e-71) {
tmp = eps * -Math.sin(x);
} else if (eps <= 1.65) {
tmp = -0.5 * Math.pow(eps, 2.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) - math.cos(x) tmp = 0 if eps <= -0.00028: tmp = t_0 elif eps <= 3.3e-71: tmp = eps * -math.sin(x) elif eps <= 1.65: tmp = -0.5 * math.pow(eps, 2.0) else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) - cos(x)) tmp = 0.0 if (eps <= -0.00028) tmp = t_0; elseif (eps <= 3.3e-71) tmp = Float64(eps * Float64(-sin(x))); elseif (eps <= 1.65) tmp = Float64(-0.5 * (eps ^ 2.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) - cos(x); tmp = 0.0; if (eps <= -0.00028) tmp = t_0; elseif (eps <= 3.3e-71) tmp = eps * -sin(x); elseif (eps <= 1.65) tmp = -0.5 * (eps ^ 2.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00028], t$95$0, If[LessEqual[eps, 3.3e-71], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 1.65], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon - \cos x\\
\mathbf{if}\;\varepsilon \leq -0.00028:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 3.3 \cdot 10^{-71}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{elif}\;\varepsilon \leq 1.65:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -2.7999999999999998e-4 or 1.6499999999999999 < eps Initial program 50.2%
Taylor expanded in x around 0 51.8%
if -2.7999999999999998e-4 < eps < 3.3000000000000002e-71Initial program 24.8%
Taylor expanded in eps around 0 86.3%
mul-1-neg86.3%
*-commutative86.3%
distribute-rgt-neg-in86.3%
Simplified86.3%
if 3.3000000000000002e-71 < eps < 1.6499999999999999Initial program 3.6%
Taylor expanded in x around 0 6.1%
Taylor expanded in eps around 0 63.7%
Final simplification68.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* -0.5 (pow eps 2.0)))
(t_1 (+ (cos eps) -1.0))
(t_2 (* eps (- (sin x)))))
(if (<= eps -0.00048)
t_1
(if (<= eps -4.9e-29)
t_2
(if (<= eps -3.2e-77)
t_0
(if (<= eps 3.3e-71) t_2 (if (<= eps 1.65) t_0 t_1)))))))
double code(double x, double eps) {
double t_0 = -0.5 * pow(eps, 2.0);
double t_1 = cos(eps) + -1.0;
double t_2 = eps * -sin(x);
double tmp;
if (eps <= -0.00048) {
tmp = t_1;
} else if (eps <= -4.9e-29) {
tmp = t_2;
} else if (eps <= -3.2e-77) {
tmp = t_0;
} else if (eps <= 3.3e-71) {
tmp = t_2;
} else if (eps <= 1.65) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = (-0.5d0) * (eps ** 2.0d0)
t_1 = cos(eps) + (-1.0d0)
t_2 = eps * -sin(x)
if (eps <= (-0.00048d0)) then
tmp = t_1
else if (eps <= (-4.9d-29)) then
tmp = t_2
else if (eps <= (-3.2d-77)) then
tmp = t_0
else if (eps <= 3.3d-71) then
tmp = t_2
else if (eps <= 1.65d0) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = -0.5 * Math.pow(eps, 2.0);
double t_1 = Math.cos(eps) + -1.0;
double t_2 = eps * -Math.sin(x);
double tmp;
if (eps <= -0.00048) {
tmp = t_1;
} else if (eps <= -4.9e-29) {
tmp = t_2;
} else if (eps <= -3.2e-77) {
tmp = t_0;
} else if (eps <= 3.3e-71) {
tmp = t_2;
} else if (eps <= 1.65) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, eps): t_0 = -0.5 * math.pow(eps, 2.0) t_1 = math.cos(eps) + -1.0 t_2 = eps * -math.sin(x) tmp = 0 if eps <= -0.00048: tmp = t_1 elif eps <= -4.9e-29: tmp = t_2 elif eps <= -3.2e-77: tmp = t_0 elif eps <= 3.3e-71: tmp = t_2 elif eps <= 1.65: tmp = t_0 else: tmp = t_1 return tmp
function code(x, eps) t_0 = Float64(-0.5 * (eps ^ 2.0)) t_1 = Float64(cos(eps) + -1.0) t_2 = Float64(eps * Float64(-sin(x))) tmp = 0.0 if (eps <= -0.00048) tmp = t_1; elseif (eps <= -4.9e-29) tmp = t_2; elseif (eps <= -3.2e-77) tmp = t_0; elseif (eps <= 3.3e-71) tmp = t_2; elseif (eps <= 1.65) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, eps) t_0 = -0.5 * (eps ^ 2.0); t_1 = cos(eps) + -1.0; t_2 = eps * -sin(x); tmp = 0.0; if (eps <= -0.00048) tmp = t_1; elseif (eps <= -4.9e-29) tmp = t_2; elseif (eps <= -3.2e-77) tmp = t_0; elseif (eps <= 3.3e-71) tmp = t_2; elseif (eps <= 1.65) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$2 = N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[eps, -0.00048], t$95$1, If[LessEqual[eps, -4.9e-29], t$95$2, If[LessEqual[eps, -3.2e-77], t$95$0, If[LessEqual[eps, 3.3e-71], t$95$2, If[LessEqual[eps, 1.65], t$95$0, t$95$1]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 \cdot {\varepsilon}^{2}\\
t_1 := \cos \varepsilon + -1\\
t_2 := \varepsilon \cdot \left(-\sin x\right)\\
\mathbf{if}\;\varepsilon \leq -0.00048:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq -4.9 \cdot 10^{-29}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;\varepsilon \leq -3.2 \cdot 10^{-77}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 3.3 \cdot 10^{-71}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;\varepsilon \leq 1.65:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if eps < -4.80000000000000012e-4 or 1.6499999999999999 < eps Initial program 50.2%
Taylor expanded in x around 0 50.8%
if -4.80000000000000012e-4 < eps < -4.8999999999999998e-29 or -3.2e-77 < eps < 3.3000000000000002e-71Initial program 27.2%
Taylor expanded in eps around 0 93.1%
mul-1-neg93.1%
*-commutative93.1%
distribute-rgt-neg-in93.1%
Simplified93.1%
if -4.8999999999999998e-29 < eps < -3.2e-77 or 3.3000000000000002e-71 < eps < 1.6499999999999999Initial program 3.8%
Taylor expanded in x around 0 5.0%
Taylor expanded in eps around 0 69.9%
Final simplification69.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.9e-17) (not (<= eps 1.65))) (+ (cos eps) -1.0) (* -0.5 (pow eps 2.0))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.9e-17) || !(eps <= 1.65)) {
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 <= (-1.9d-17)) .or. (.not. (eps <= 1.65d0))) 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 <= -1.9e-17) || !(eps <= 1.65)) {
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 <= -1.9e-17) or not (eps <= 1.65): 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 <= -1.9e-17) || !(eps <= 1.65)) 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 <= -1.9e-17) || ~((eps <= 1.65))) tmp = cos(eps) + -1.0; else tmp = -0.5 * (eps ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.9e-17], N[Not[LessEqual[eps, 1.65]], $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 -1.9 \cdot 10^{-17} \lor \neg \left(\varepsilon \leq 1.65\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\end{array}
\end{array}
if eps < -1.9000000000000001e-17 or 1.6499999999999999 < eps Initial program 49.1%
Taylor expanded in x around 0 49.7%
if -1.9000000000000001e-17 < eps < 1.6499999999999999Initial program 23.4%
Taylor expanded in x around 0 23.7%
Taylor expanded in eps around 0 40.4%
Final simplification45.2%
(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 36.7%
Taylor expanded in x around 0 37.1%
Final simplification37.1%
(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 36.7%
sub-neg36.7%
+-commutative36.7%
add-log-exp36.6%
add-log-exp36.5%
sum-log36.5%
Applied egg-rr36.5%
Taylor expanded in eps around 0 13.0%
exp-neg13.0%
rgt-mult-inverse13.0%
metadata-eval13.0%
Simplified13.0%
Final simplification13.0%
herbie shell --seed 2023319
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))