
(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 15 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) (sin x))))
(if (<= eps -0.0055)
(- (- (* (cos x) (cos eps)) (cos x)) t_0)
(if (<= eps 0.0045)
(-
(*
(cos x)
(+ (* -0.5 (pow eps 2.0)) (* 0.041666666666666664 (pow eps 4.0))))
t_0)
(- (fma (cos x) (cos eps) (* (sin eps) (- (sin x)))) (cos x))))))
double code(double x, double eps) {
double t_0 = sin(eps) * sin(x);
double tmp;
if (eps <= -0.0055) {
tmp = ((cos(x) * cos(eps)) - cos(x)) - t_0;
} else if (eps <= 0.0045) {
tmp = (cos(x) * ((-0.5 * pow(eps, 2.0)) + (0.041666666666666664 * pow(eps, 4.0)))) - t_0;
} else {
tmp = fma(cos(x), cos(eps), (sin(eps) * -sin(x))) - cos(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64(sin(eps) * sin(x)) tmp = 0.0 if (eps <= -0.0055) tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - cos(x)) - t_0); elseif (eps <= 0.0045) tmp = Float64(Float64(cos(x) * Float64(Float64(-0.5 * (eps ^ 2.0)) + Float64(0.041666666666666664 * (eps ^ 4.0)))) - t_0); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(eps) * Float64(-sin(x)))) - cos(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.0055], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], If[LessEqual[eps, 0.0045], 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] - t$95$0), $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}
t_0 := \sin \varepsilon \cdot \sin x\\
\mathbf{if}\;\varepsilon \leq -0.0055:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \cos x\right) - t_0\\
\mathbf{elif}\;\varepsilon \leq 0.0045:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2} + 0.041666666666666664 \cdot {\varepsilon}^{4}\right) - t_0\\
\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.0054999999999999997Initial program 62.6%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.7%
Applied egg-rr98.7%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
+-commutative98.7%
sub-neg98.7%
*-commutative98.7%
associate--r+98.7%
+-commutative98.7%
associate--r+98.8%
*-rgt-identity98.8%
distribute-lft-out--98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
*-commutative98.8%
Simplified98.8%
+-commutative98.8%
distribute-rgt-in98.8%
neg-mul-198.8%
Applied egg-rr98.8%
Taylor expanded in eps around inf 98.8%
if -0.0054999999999999997 < eps < 0.00449999999999999966Initial program 24.9%
cos-sum26.1%
cancel-sign-sub-inv26.1%
fma-def26.1%
Applied egg-rr26.1%
Taylor expanded in x around inf 26.1%
neg-mul-126.1%
+-commutative26.1%
sub-neg26.1%
*-commutative26.1%
associate--r+26.1%
+-commutative26.1%
associate--r+83.4%
*-rgt-identity83.4%
distribute-lft-out--83.4%
sub-neg83.4%
metadata-eval83.4%
+-commutative83.4%
*-commutative83.4%
Simplified83.4%
Taylor expanded in eps around 0 99.8%
if 0.00449999999999999966 < eps Initial program 49.8%
cos-sum99.1%
cancel-sign-sub-inv99.1%
fma-def99.1%
Applied egg-rr99.1%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (- (/ (* (pow (sin eps) 2.0) (cos x)) (- -1.0 (cos eps))) (* (sin eps) (sin x))))
double code(double x, double eps) {
return ((pow(sin(eps), 2.0) * cos(x)) / (-1.0 - cos(eps))) - (sin(eps) * sin(x));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((sin(eps) ** 2.0d0) * cos(x)) / ((-1.0d0) - cos(eps))) - (sin(eps) * sin(x))
end function
public static double code(double x, double eps) {
return ((Math.pow(Math.sin(eps), 2.0) * Math.cos(x)) / (-1.0 - Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
}
def code(x, eps): return ((math.pow(math.sin(eps), 2.0) * math.cos(x)) / (-1.0 - math.cos(eps))) - (math.sin(eps) * math.sin(x))
function code(x, eps) return Float64(Float64(Float64((sin(eps) ^ 2.0) * cos(x)) / Float64(-1.0 - cos(eps))) - Float64(sin(eps) * sin(x))) end
function tmp = code(x, eps) tmp = (((sin(eps) ^ 2.0) * cos(x)) / (-1.0 - cos(eps))) - (sin(eps) * sin(x)); end
code[x_, eps_] := N[(N[(N[(N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(-1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\sin \varepsilon}^{2} \cdot \cos x}{-1 - \cos \varepsilon} - \sin \varepsilon \cdot \sin x
\end{array}
Initial program 40.1%
cos-sum63.1%
cancel-sign-sub-inv63.1%
fma-def63.1%
Applied egg-rr63.1%
Taylor expanded in x around inf 63.1%
neg-mul-163.1%
+-commutative63.1%
sub-neg63.1%
*-commutative63.1%
associate--r+63.1%
+-commutative63.1%
associate--r+91.3%
*-rgt-identity91.3%
distribute-lft-out--91.3%
sub-neg91.3%
metadata-eval91.3%
+-commutative91.3%
*-commutative91.3%
Simplified91.3%
*-commutative91.3%
flip-+90.8%
associate-*l/90.8%
metadata-eval90.8%
1-sub-cos98.8%
pow298.8%
Applied egg-rr98.8%
Final simplification98.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (cos x) (cos eps))) (t_1 (* (sin eps) (sin x))))
(if (<= eps -0.0055)
(- (- t_0 (cos x)) t_1)
(if (<= eps 0.0052)
(-
(*
(cos x)
(+ (* -0.5 (pow eps 2.0)) (* 0.041666666666666664 (pow eps 4.0))))
t_1)
(- t_0 (+ (cos x) t_1))))))
double code(double x, double eps) {
double t_0 = cos(x) * cos(eps);
double t_1 = sin(eps) * sin(x);
double tmp;
if (eps <= -0.0055) {
tmp = (t_0 - cos(x)) - t_1;
} else if (eps <= 0.0052) {
tmp = (cos(x) * ((-0.5 * pow(eps, 2.0)) + (0.041666666666666664 * pow(eps, 4.0)))) - t_1;
} else {
tmp = t_0 - (cos(x) + 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) :: tmp
t_0 = cos(x) * cos(eps)
t_1 = sin(eps) * sin(x)
if (eps <= (-0.0055d0)) then
tmp = (t_0 - cos(x)) - t_1
else if (eps <= 0.0052d0) then
tmp = (cos(x) * (((-0.5d0) * (eps ** 2.0d0)) + (0.041666666666666664d0 * (eps ** 4.0d0)))) - t_1
else
tmp = t_0 - (cos(x) + t_1)
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(eps) * Math.sin(x);
double tmp;
if (eps <= -0.0055) {
tmp = (t_0 - Math.cos(x)) - t_1;
} else if (eps <= 0.0052) {
tmp = (Math.cos(x) * ((-0.5 * Math.pow(eps, 2.0)) + (0.041666666666666664 * Math.pow(eps, 4.0)))) - t_1;
} else {
tmp = t_0 - (Math.cos(x) + t_1);
}
return tmp;
}
def code(x, eps): t_0 = math.cos(x) * math.cos(eps) t_1 = math.sin(eps) * math.sin(x) tmp = 0 if eps <= -0.0055: tmp = (t_0 - math.cos(x)) - t_1 elif eps <= 0.0052: tmp = (math.cos(x) * ((-0.5 * math.pow(eps, 2.0)) + (0.041666666666666664 * math.pow(eps, 4.0)))) - t_1 else: tmp = t_0 - (math.cos(x) + t_1) return tmp
function code(x, eps) t_0 = Float64(cos(x) * cos(eps)) t_1 = Float64(sin(eps) * sin(x)) tmp = 0.0 if (eps <= -0.0055) tmp = Float64(Float64(t_0 - cos(x)) - t_1); elseif (eps <= 0.0052) tmp = Float64(Float64(cos(x) * Float64(Float64(-0.5 * (eps ^ 2.0)) + Float64(0.041666666666666664 * (eps ^ 4.0)))) - t_1); else tmp = Float64(t_0 - Float64(cos(x) + t_1)); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(x) * cos(eps); t_1 = sin(eps) * sin(x); tmp = 0.0; if (eps <= -0.0055) tmp = (t_0 - cos(x)) - t_1; elseif (eps <= 0.0052) tmp = (cos(x) * ((-0.5 * (eps ^ 2.0)) + (0.041666666666666664 * (eps ^ 4.0)))) - t_1; else tmp = t_0 - (cos(x) + t_1); 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[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.0055], N[(N[(t$95$0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision], If[LessEqual[eps, 0.0052], 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] - t$95$1), $MachinePrecision], N[(t$95$0 - N[(N[Cos[x], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \cos \varepsilon\\
t_1 := \sin \varepsilon \cdot \sin x\\
\mathbf{if}\;\varepsilon \leq -0.0055:\\
\;\;\;\;\left(t_0 - \cos x\right) - t_1\\
\mathbf{elif}\;\varepsilon \leq 0.0052:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2} + 0.041666666666666664 \cdot {\varepsilon}^{4}\right) - t_1\\
\mathbf{else}:\\
\;\;\;\;t_0 - \left(\cos x + t_1\right)\\
\end{array}
\end{array}
if eps < -0.0054999999999999997Initial program 62.6%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.7%
Applied egg-rr98.7%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
+-commutative98.7%
sub-neg98.7%
*-commutative98.7%
associate--r+98.7%
+-commutative98.7%
associate--r+98.8%
*-rgt-identity98.8%
distribute-lft-out--98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
*-commutative98.8%
Simplified98.8%
+-commutative98.8%
distribute-rgt-in98.8%
neg-mul-198.8%
Applied egg-rr98.8%
Taylor expanded in eps around inf 98.8%
if -0.0054999999999999997 < eps < 0.0051999999999999998Initial program 24.9%
cos-sum26.1%
cancel-sign-sub-inv26.1%
fma-def26.1%
Applied egg-rr26.1%
Taylor expanded in x around inf 26.1%
neg-mul-126.1%
+-commutative26.1%
sub-neg26.1%
*-commutative26.1%
associate--r+26.1%
+-commutative26.1%
associate--r+83.4%
*-rgt-identity83.4%
distribute-lft-out--83.4%
sub-neg83.4%
metadata-eval83.4%
+-commutative83.4%
*-commutative83.4%
Simplified83.4%
Taylor expanded in eps around 0 99.8%
if 0.0051999999999999998 < eps Initial program 49.8%
add-log-exp49.8%
Applied egg-rr49.8%
rem-log-exp49.8%
cos-sum99.1%
associate--l-99.1%
add-sqr-sqrt48.2%
sqrt-unprod75.4%
sqr-neg75.4%
sqrt-unprod27.2%
add-sqr-sqrt51.6%
*-commutative51.6%
add-sqr-sqrt27.2%
sqrt-unprod75.4%
sqr-neg75.4%
sqrt-unprod48.2%
add-sqr-sqrt99.1%
Applied egg-rr99.1%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(if (<= x -6.4e-15)
(fma (+ -1.0 (cos eps)) (cos x) (* (sin eps) (- (sin x))))
(if (<= x 4.8e-33)
(* (* (sin (* (+ eps (- x x)) 0.5)) (sin (* 0.5 (+ eps (+ x x))))) -2.0)
(- (- (* (cos x) (cos eps)) (cos x)) (* (sin eps) (sin x))))))
double code(double x, double eps) {
double tmp;
if (x <= -6.4e-15) {
tmp = fma((-1.0 + cos(eps)), cos(x), (sin(eps) * -sin(x)));
} else if (x <= 4.8e-33) {
tmp = (sin(((eps + (x - x)) * 0.5)) * sin((0.5 * (eps + (x + x))))) * -2.0;
} else {
tmp = ((cos(x) * cos(eps)) - cos(x)) - (sin(eps) * sin(x));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -6.4e-15) tmp = fma(Float64(-1.0 + cos(eps)), cos(x), Float64(sin(eps) * Float64(-sin(x)))); elseif (x <= 4.8e-33) tmp = Float64(Float64(sin(Float64(Float64(eps + Float64(x - x)) * 0.5)) * sin(Float64(0.5 * Float64(eps + Float64(x + x))))) * -2.0); else tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - cos(x)) - Float64(sin(eps) * sin(x))); end return tmp end
code[x_, eps_] := If[LessEqual[x, -6.4e-15], N[(N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.8e-33], N[(N[(N[Sin[N[(N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision], 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]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(-1 + \cos \varepsilon, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{-33}:\\
\;\;\;\;\left(\sin \left(\left(\varepsilon + \left(x - x\right)\right) \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)\right) \cdot -2\\
\mathbf{else}:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \cos x\right) - \sin \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if x < -6.3999999999999999e-15Initial program 9.2%
cos-sum50.7%
cancel-sign-sub-inv50.7%
fma-def50.7%
Applied egg-rr50.7%
Taylor expanded in x around inf 50.7%
neg-mul-150.7%
+-commutative50.7%
sub-neg50.7%
*-commutative50.7%
associate--r+50.6%
+-commutative50.6%
associate--r+99.5%
*-rgt-identity99.5%
distribute-lft-out--99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
*-commutative99.5%
Simplified99.5%
*-commutative99.5%
fma-neg99.5%
distribute-rgt-neg-in99.5%
Applied egg-rr99.5%
if -6.3999999999999999e-15 < x < 4.8e-33Initial program 77.0%
cos-sum77.0%
cancel-sign-sub-inv77.0%
fma-def77.0%
Applied egg-rr77.0%
Taylor expanded in x around inf 77.0%
neg-mul-177.0%
+-commutative77.0%
sub-neg77.0%
*-commutative77.0%
associate--r+77.0%
+-commutative77.0%
associate--r+81.7%
*-rgt-identity81.7%
distribute-lft-out--81.7%
sub-neg81.7%
metadata-eval81.7%
+-commutative81.7%
*-commutative81.7%
Simplified81.7%
distribute-lft-in81.7%
associate--l+77.0%
*-commutative77.0%
neg-mul-177.0%
cos-sum77.0%
+-commutative77.0%
sub-neg77.0%
diff-cos94.9%
*-commutative94.9%
Applied egg-rr99.6%
if 4.8e-33 < x Initial program 11.0%
cos-sum53.0%
cancel-sign-sub-inv53.0%
fma-def53.0%
Applied egg-rr53.0%
Taylor expanded in x around inf 53.0%
neg-mul-153.0%
+-commutative53.0%
sub-neg53.0%
*-commutative53.0%
associate--r+53.0%
+-commutative53.0%
associate--r+98.8%
*-rgt-identity98.8%
distribute-lft-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
Simplified98.7%
+-commutative98.7%
distribute-rgt-in98.8%
neg-mul-198.8%
Applied egg-rr98.8%
Taylor expanded in eps around inf 98.8%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))))
(if (<= x -2.05e-14)
(fma t_0 (cos x) (* (sin eps) (- (sin x))))
(if (<= x 1.6e-34)
(* (* (sin (* (+ eps (- x x)) 0.5)) (sin (* 0.5 (+ eps (+ x x))))) -2.0)
(- (* (cos x) t_0) (* (sin eps) (sin x)))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double tmp;
if (x <= -2.05e-14) {
tmp = fma(t_0, cos(x), (sin(eps) * -sin(x)));
} else if (x <= 1.6e-34) {
tmp = (sin(((eps + (x - x)) * 0.5)) * sin((0.5 * (eps + (x + x))))) * -2.0;
} else {
tmp = (cos(x) * t_0) - (sin(eps) * sin(x));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) tmp = 0.0 if (x <= -2.05e-14) tmp = fma(t_0, cos(x), Float64(sin(eps) * Float64(-sin(x)))); elseif (x <= 1.6e-34) tmp = Float64(Float64(sin(Float64(Float64(eps + Float64(x - x)) * 0.5)) * sin(Float64(0.5 * Float64(eps + Float64(x + x))))) * -2.0); else tmp = Float64(Float64(cos(x) * t_0) - Float64(sin(eps) * sin(x))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.05e-14], N[(t$95$0 * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.6e-34], N[(N[(N[Sin[N[(N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
\mathbf{if}\;x \leq -2.05 \cdot 10^{-14}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-34}:\\
\;\;\;\;\left(\sin \left(\left(\varepsilon + \left(x - x\right)\right) \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)\right) \cdot -2\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot t_0 - \sin \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if x < -2.0500000000000001e-14Initial program 9.2%
cos-sum50.7%
cancel-sign-sub-inv50.7%
fma-def50.7%
Applied egg-rr50.7%
Taylor expanded in x around inf 50.7%
neg-mul-150.7%
+-commutative50.7%
sub-neg50.7%
*-commutative50.7%
associate--r+50.6%
+-commutative50.6%
associate--r+99.5%
*-rgt-identity99.5%
distribute-lft-out--99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
*-commutative99.5%
Simplified99.5%
*-commutative99.5%
fma-neg99.5%
distribute-rgt-neg-in99.5%
Applied egg-rr99.5%
if -2.0500000000000001e-14 < x < 1.60000000000000001e-34Initial program 77.0%
cos-sum77.0%
cancel-sign-sub-inv77.0%
fma-def77.0%
Applied egg-rr77.0%
Taylor expanded in x around inf 77.0%
neg-mul-177.0%
+-commutative77.0%
sub-neg77.0%
*-commutative77.0%
associate--r+77.0%
+-commutative77.0%
associate--r+81.7%
*-rgt-identity81.7%
distribute-lft-out--81.7%
sub-neg81.7%
metadata-eval81.7%
+-commutative81.7%
*-commutative81.7%
Simplified81.7%
distribute-lft-in81.7%
associate--l+77.0%
*-commutative77.0%
neg-mul-177.0%
cos-sum77.0%
+-commutative77.0%
sub-neg77.0%
diff-cos94.9%
*-commutative94.9%
Applied egg-rr99.6%
if 1.60000000000000001e-34 < x Initial program 11.0%
cos-sum53.0%
cancel-sign-sub-inv53.0%
fma-def53.0%
Applied egg-rr53.0%
Taylor expanded in x around inf 53.0%
neg-mul-153.0%
+-commutative53.0%
sub-neg53.0%
*-commutative53.0%
associate--r+53.0%
+-commutative53.0%
associate--r+98.8%
*-rgt-identity98.8%
distribute-lft-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
Simplified98.7%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (or (<= x -1.25e-16) (not (<= x 1.6e-31))) (- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x))) (* (* (sin (* (+ eps (- x x)) 0.5)) (sin (* 0.5 (+ eps (+ x x))))) -2.0)))
double code(double x, double eps) {
double tmp;
if ((x <= -1.25e-16) || !(x <= 1.6e-31)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = (sin(((eps + (x - x)) * 0.5)) * sin((0.5 * (eps + (x + 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 ((x <= (-1.25d-16)) .or. (.not. (x <= 1.6d-31))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = (sin(((eps + (x - x)) * 0.5d0)) * sin((0.5d0 * (eps + (x + x))))) * (-2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -1.25e-16) || !(x <= 1.6e-31)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = (Math.sin(((eps + (x - x)) * 0.5)) * Math.sin((0.5 * (eps + (x + x))))) * -2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -1.25e-16) or not (x <= 1.6e-31): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = (math.sin(((eps + (x - x)) * 0.5)) * math.sin((0.5 * (eps + (x + x))))) * -2.0 return tmp
function code(x, eps) tmp = 0.0 if ((x <= -1.25e-16) || !(x <= 1.6e-31)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(sin(Float64(Float64(eps + Float64(x - x)) * 0.5)) * sin(Float64(0.5 * Float64(eps + Float64(x + x))))) * -2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -1.25e-16) || ~((x <= 1.6e-31))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = (sin(((eps + (x - x)) * 0.5)) * sin((0.5 * (eps + (x + x))))) * -2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -1.25e-16], N[Not[LessEqual[x, 1.6e-31]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[N[(N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-16} \lor \neg \left(x \leq 1.6 \cdot 10^{-31}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(\sin \left(\left(\varepsilon + \left(x - x\right)\right) \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)\right) \cdot -2\\
\end{array}
\end{array}
if x < -1.2500000000000001e-16 or 1.60000000000000009e-31 < x Initial program 10.1%
cos-sum51.8%
cancel-sign-sub-inv51.8%
fma-def51.8%
Applied egg-rr51.8%
Taylor expanded in x around inf 51.8%
neg-mul-151.8%
+-commutative51.8%
sub-neg51.8%
*-commutative51.8%
associate--r+51.8%
+-commutative51.8%
associate--r+99.2%
*-rgt-identity99.2%
distribute-lft-out--99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
*-commutative99.1%
Simplified99.1%
if -1.2500000000000001e-16 < x < 1.60000000000000009e-31Initial program 77.0%
cos-sum77.0%
cancel-sign-sub-inv77.0%
fma-def77.0%
Applied egg-rr77.0%
Taylor expanded in x around inf 77.0%
neg-mul-177.0%
+-commutative77.0%
sub-neg77.0%
*-commutative77.0%
associate--r+77.0%
+-commutative77.0%
associate--r+81.7%
*-rgt-identity81.7%
distribute-lft-out--81.7%
sub-neg81.7%
metadata-eval81.7%
+-commutative81.7%
*-commutative81.7%
Simplified81.7%
distribute-lft-in81.7%
associate--l+77.0%
*-commutative77.0%
neg-mul-177.0%
cos-sum77.0%
+-commutative77.0%
sub-neg77.0%
diff-cos94.9%
*-commutative94.9%
Applied egg-rr99.6%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))) (t_1 (* (sin x) (* -2.0 t_0))))
(if (<= x -5.2e-18)
t_1
(if (<= x 1.76e-124)
(* -2.0 (pow t_0 2.0))
(if (<= x 0.0028) (- (+ -1.0 (cos eps)) (* (sin eps) x)) t_1)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double t_1 = sin(x) * (-2.0 * t_0);
double tmp;
if (x <= -5.2e-18) {
tmp = t_1;
} else if (x <= 1.76e-124) {
tmp = -2.0 * pow(t_0, 2.0);
} else if (x <= 0.0028) {
tmp = (-1.0 + cos(eps)) - (sin(eps) * x);
} 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) :: tmp
t_0 = sin((eps * 0.5d0))
t_1 = sin(x) * ((-2.0d0) * t_0)
if (x <= (-5.2d-18)) then
tmp = t_1
else if (x <= 1.76d-124) then
tmp = (-2.0d0) * (t_0 ** 2.0d0)
else if (x <= 0.0028d0) then
tmp = ((-1.0d0) + cos(eps)) - (sin(eps) * x)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
double t_1 = Math.sin(x) * (-2.0 * t_0);
double tmp;
if (x <= -5.2e-18) {
tmp = t_1;
} else if (x <= 1.76e-124) {
tmp = -2.0 * Math.pow(t_0, 2.0);
} else if (x <= 0.0028) {
tmp = (-1.0 + Math.cos(eps)) - (Math.sin(eps) * x);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) t_1 = math.sin(x) * (-2.0 * t_0) tmp = 0 if x <= -5.2e-18: tmp = t_1 elif x <= 1.76e-124: tmp = -2.0 * math.pow(t_0, 2.0) elif x <= 0.0028: tmp = (-1.0 + math.cos(eps)) - (math.sin(eps) * x) else: tmp = t_1 return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) t_1 = Float64(sin(x) * Float64(-2.0 * t_0)) tmp = 0.0 if (x <= -5.2e-18) tmp = t_1; elseif (x <= 1.76e-124) tmp = Float64(-2.0 * (t_0 ^ 2.0)); elseif (x <= 0.0028) tmp = Float64(Float64(-1.0 + cos(eps)) - Float64(sin(eps) * x)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); t_1 = sin(x) * (-2.0 * t_0); tmp = 0.0; if (x <= -5.2e-18) tmp = t_1; elseif (x <= 1.76e-124) tmp = -2.0 * (t_0 ^ 2.0); elseif (x <= 0.0028) tmp = (-1.0 + cos(eps)) - (sin(eps) * x); else tmp = t_1; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[x], $MachinePrecision] * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.2e-18], t$95$1, If[LessEqual[x, 1.76e-124], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.0028], N[(N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
t_1 := \sin x \cdot \left(-2 \cdot t_0\right)\\
\mathbf{if}\;x \leq -5.2 \cdot 10^{-18}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.76 \cdot 10^{-124}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\mathbf{elif}\;x \leq 0.0028:\\
\;\;\;\;\left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot x\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if x < -5.2000000000000001e-18 or 0.00279999999999999997 < x Initial program 9.1%
diff-cos7.5%
div-inv7.5%
associate--l+7.5%
metadata-eval7.5%
div-inv7.5%
+-commutative7.5%
associate-+l+7.6%
metadata-eval7.6%
Applied egg-rr7.6%
associate-*r*7.6%
*-commutative7.6%
*-commutative7.6%
+-commutative7.6%
count-27.6%
fma-def7.6%
sub-neg7.6%
mul-1-neg7.6%
+-commutative7.6%
associate-+r+57.3%
mul-1-neg57.3%
sub-neg57.3%
+-inverses57.3%
remove-double-neg57.3%
mul-1-neg57.3%
sub-neg57.3%
neg-sub057.3%
mul-1-neg57.3%
remove-double-neg57.3%
Simplified57.3%
Taylor expanded in eps around 0 56.5%
if -5.2000000000000001e-18 < x < 1.75999999999999996e-124Initial program 79.3%
diff-cos99.2%
div-inv99.2%
associate--l+99.2%
metadata-eval99.2%
div-inv99.2%
+-commutative99.2%
associate-+l+99.2%
metadata-eval99.2%
Applied egg-rr99.2%
associate-*r*99.2%
*-commutative99.2%
*-commutative99.2%
+-commutative99.2%
count-299.2%
fma-def99.2%
sub-neg99.2%
mul-1-neg99.2%
+-commutative99.2%
associate-+r+99.6%
mul-1-neg99.6%
sub-neg99.6%
+-inverses99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
neg-sub099.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 98.5%
if 1.75999999999999996e-124 < x < 0.00279999999999999997Initial program 59.2%
Taylor expanded in x around 0 62.1%
sub-neg62.1%
metadata-eval62.1%
+-commutative62.1%
associate-+r+91.2%
+-commutative91.2%
+-commutative91.2%
mul-1-neg91.2%
unsub-neg91.2%
unpow291.2%
associate-*l*91.2%
distribute-lft-out--91.2%
+-commutative91.2%
*-commutative91.2%
fma-def91.2%
Simplified91.2%
Taylor expanded in x around 0 90.1%
mul-1-neg90.1%
distribute-rgt-neg-out90.1%
Simplified90.1%
Final simplification75.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (cos eps) (cos x))))
(if (<= eps -2.9e-5)
t_0
(if (<= eps 4.6e-17)
(* (sin x) (- eps))
(if (<= eps 0.00014) (* -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 <= -2.9e-5) {
tmp = t_0;
} else if (eps <= 4.6e-17) {
tmp = sin(x) * -eps;
} else if (eps <= 0.00014) {
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 <= (-2.9d-5)) then
tmp = t_0
else if (eps <= 4.6d-17) then
tmp = sin(x) * -eps
else if (eps <= 0.00014d0) 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 <= -2.9e-5) {
tmp = t_0;
} else if (eps <= 4.6e-17) {
tmp = Math.sin(x) * -eps;
} else if (eps <= 0.00014) {
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 <= -2.9e-5: tmp = t_0 elif eps <= 4.6e-17: tmp = math.sin(x) * -eps elif eps <= 0.00014: 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 <= -2.9e-5) tmp = t_0; elseif (eps <= 4.6e-17) tmp = Float64(sin(x) * Float64(-eps)); elseif (eps <= 0.00014) 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 <= -2.9e-5) tmp = t_0; elseif (eps <= 4.6e-17) tmp = sin(x) * -eps; elseif (eps <= 0.00014) 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, -2.9e-5], t$95$0, If[LessEqual[eps, 4.6e-17], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], If[LessEqual[eps, 0.00014], 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 -2.9 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 4.6 \cdot 10^{-17}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00014:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -2.9e-5 or 1.3999999999999999e-4 < eps Initial program 54.5%
Taylor expanded in x around 0 56.9%
if -2.9e-5 < eps < 4.60000000000000018e-17Initial program 25.7%
Taylor expanded in eps around 0 86.6%
mul-1-neg86.6%
*-commutative86.6%
distribute-rgt-neg-in86.6%
Simplified86.6%
if 4.60000000000000018e-17 < eps < 1.3999999999999999e-4Initial program 13.0%
Taylor expanded in x around 0 13.0%
Taylor expanded in eps around 0 97.5%
Final simplification71.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -3e-20) (not (<= x 6e-31)))
(* (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 <= -3e-20) || !(x <= 6e-31)) {
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 <= (-3d-20)) .or. (.not. (x <= 6d-31))) 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 <= -3e-20) || !(x <= 6e-31)) {
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 <= -3e-20) or not (x <= 6e-31): 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 <= -3e-20) || !(x <= 6e-31)) 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 <= -3e-20) || ~((x <= 6e-31))) 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, -3e-20], N[Not[LessEqual[x, 6e-31]], $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 -3 \cdot 10^{-20} \lor \neg \left(x \leq 6 \cdot 10^{-31}\right):\\
\;\;\;\;\sin x \cdot \left(-2 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -3.00000000000000029e-20 or 5.99999999999999962e-31 < x Initial program 10.1%
diff-cos8.6%
div-inv8.6%
associate--l+8.6%
metadata-eval8.6%
div-inv8.6%
+-commutative8.6%
associate-+l+8.7%
metadata-eval8.7%
Applied egg-rr8.7%
associate-*r*8.7%
*-commutative8.7%
*-commutative8.7%
+-commutative8.7%
count-28.7%
fma-def8.7%
sub-neg8.7%
mul-1-neg8.7%
+-commutative8.7%
associate-+r+58.5%
mul-1-neg58.5%
sub-neg58.5%
+-inverses58.5%
remove-double-neg58.5%
mul-1-neg58.5%
sub-neg58.5%
neg-sub058.5%
mul-1-neg58.5%
remove-double-neg58.5%
Simplified58.5%
Taylor expanded in eps around 0 56.7%
if -3.00000000000000029e-20 < x < 5.99999999999999962e-31Initial program 77.6%
diff-cos95.7%
div-inv95.7%
associate--l+95.7%
metadata-eval95.7%
div-inv95.7%
+-commutative95.7%
associate-+l+95.7%
metadata-eval95.7%
Applied egg-rr95.7%
associate-*r*95.7%
*-commutative95.7%
*-commutative95.7%
+-commutative95.7%
count-295.7%
fma-def95.7%
sub-neg95.7%
mul-1-neg95.7%
+-commutative95.7%
associate-+r+99.6%
mul-1-neg99.6%
sub-neg99.6%
+-inverses99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
neg-sub099.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 95.2%
Final simplification73.9%
(FPCore (x eps) :precision binary64 (* (* (sin (* (+ eps (- x x)) 0.5)) (sin (* 0.5 (+ eps (+ x x))))) -2.0))
double code(double x, double eps) {
return (sin(((eps + (x - x)) * 0.5)) * sin((0.5 * (eps + (x + x))))) * -2.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (sin(((eps + (x - x)) * 0.5d0)) * sin((0.5d0 * (eps + (x + x))))) * (-2.0d0)
end function
public static double code(double x, double eps) {
return (Math.sin(((eps + (x - x)) * 0.5)) * Math.sin((0.5 * (eps + (x + x))))) * -2.0;
}
def code(x, eps): return (math.sin(((eps + (x - x)) * 0.5)) * math.sin((0.5 * (eps + (x + x))))) * -2.0
function code(x, eps) return Float64(Float64(sin(Float64(Float64(eps + Float64(x - x)) * 0.5)) * sin(Float64(0.5 * Float64(eps + Float64(x + x))))) * -2.0) end
function tmp = code(x, eps) tmp = (sin(((eps + (x - x)) * 0.5)) * sin((0.5 * (eps + (x + x))))) * -2.0; end
code[x_, eps_] := N[(N[(N[Sin[N[(N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\sin \left(\left(\varepsilon + \left(x - x\right)\right) \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)\right) \cdot -2
\end{array}
Initial program 40.1%
cos-sum63.1%
cancel-sign-sub-inv63.1%
fma-def63.1%
Applied egg-rr63.1%
Taylor expanded in x around inf 63.1%
neg-mul-163.1%
+-commutative63.1%
sub-neg63.1%
*-commutative63.1%
associate--r+63.1%
+-commutative63.1%
associate--r+91.3%
*-rgt-identity91.3%
distribute-lft-out--91.3%
sub-neg91.3%
metadata-eval91.3%
+-commutative91.3%
*-commutative91.3%
Simplified91.3%
distribute-lft-in91.3%
associate--l+63.1%
*-commutative63.1%
neg-mul-163.1%
cos-sum40.1%
+-commutative40.1%
sub-neg40.1%
diff-cos47.4%
*-commutative47.4%
Applied egg-rr76.8%
Final simplification76.8%
(FPCore (x eps) :precision binary64 (if (or (<= x -1.85e-17) (not (<= x 4e-41))) (* (sin x) (- eps)) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -1.85e-17) || !(x <= 4e-41)) {
tmp = sin(x) * -eps;
} 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 ((x <= (-1.85d-17)) .or. (.not. (x <= 4d-41))) then
tmp = sin(x) * -eps
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 ((x <= -1.85e-17) || !(x <= 4e-41)) {
tmp = Math.sin(x) * -eps;
} else {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -1.85e-17) or not (x <= 4e-41): tmp = math.sin(x) * -eps else: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -1.85e-17) || !(x <= 4e-41)) tmp = Float64(sin(x) * Float64(-eps)); 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 ((x <= -1.85e-17) || ~((x <= 4e-41))) tmp = sin(x) * -eps; else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -1.85e-17], N[Not[LessEqual[x, 4e-41]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * (-eps)), $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}\;x \leq -1.85 \cdot 10^{-17} \lor \neg \left(x \leq 4 \cdot 10^{-41}\right):\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if x < -1.8499999999999999e-17 or 4.00000000000000002e-41 < x Initial program 10.1%
Taylor expanded in eps around 0 52.7%
mul-1-neg52.7%
*-commutative52.7%
distribute-rgt-neg-in52.7%
Simplified52.7%
if -1.8499999999999999e-17 < x < 4.00000000000000002e-41Initial program 77.6%
diff-cos95.7%
div-inv95.7%
associate--l+95.7%
metadata-eval95.7%
div-inv95.7%
+-commutative95.7%
associate-+l+95.7%
metadata-eval95.7%
Applied egg-rr95.7%
associate-*r*95.7%
*-commutative95.7%
*-commutative95.7%
+-commutative95.7%
count-295.7%
fma-def95.7%
sub-neg95.7%
mul-1-neg95.7%
+-commutative95.7%
associate-+r+99.6%
mul-1-neg99.6%
sub-neg99.6%
+-inverses99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
neg-sub099.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 95.2%
Final simplification71.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))))
(if (<= eps -0.00078)
t_0
(if (<= eps 3.6e-18)
(* (sin x) (- eps))
(if (<= eps 0.000135) (* -0.5 (pow eps 2.0)) t_0)))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double tmp;
if (eps <= -0.00078) {
tmp = t_0;
} else if (eps <= 3.6e-18) {
tmp = sin(x) * -eps;
} else if (eps <= 0.000135) {
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 = (-1.0d0) + cos(eps)
if (eps <= (-0.00078d0)) then
tmp = t_0
else if (eps <= 3.6d-18) then
tmp = sin(x) * -eps
else if (eps <= 0.000135d0) 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 = -1.0 + Math.cos(eps);
double tmp;
if (eps <= -0.00078) {
tmp = t_0;
} else if (eps <= 3.6e-18) {
tmp = Math.sin(x) * -eps;
} else if (eps <= 0.000135) {
tmp = -0.5 * Math.pow(eps, 2.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) tmp = 0 if eps <= -0.00078: tmp = t_0 elif eps <= 3.6e-18: tmp = math.sin(x) * -eps elif eps <= 0.000135: tmp = -0.5 * math.pow(eps, 2.0) else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) tmp = 0.0 if (eps <= -0.00078) tmp = t_0; elseif (eps <= 3.6e-18) tmp = Float64(sin(x) * Float64(-eps)); elseif (eps <= 0.000135) tmp = Float64(-0.5 * (eps ^ 2.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = -1.0 + cos(eps); tmp = 0.0; if (eps <= -0.00078) tmp = t_0; elseif (eps <= 3.6e-18) tmp = sin(x) * -eps; elseif (eps <= 0.000135) tmp = -0.5 * (eps ^ 2.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00078], t$95$0, If[LessEqual[eps, 3.6e-18], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], If[LessEqual[eps, 0.000135], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.00078:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 3.6 \cdot 10^{-18}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 0.000135:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -7.79999999999999986e-4 or 1.35000000000000002e-4 < eps Initial program 54.5%
Taylor expanded in x around 0 54.6%
if -7.79999999999999986e-4 < eps < 3.6000000000000001e-18Initial program 25.7%
Taylor expanded in eps around 0 86.6%
mul-1-neg86.6%
*-commutative86.6%
distribute-rgt-neg-in86.6%
Simplified86.6%
if 3.6000000000000001e-18 < eps < 1.35000000000000002e-4Initial program 13.0%
Taylor expanded in x around 0 13.0%
Taylor expanded in eps around 0 97.5%
Final simplification70.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.00012) (not (<= eps 0.000135))) (+ -1.0 (cos eps)) (* -0.5 (pow eps 2.0))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00012) || !(eps <= 0.000135)) {
tmp = -1.0 + cos(eps);
} else {
tmp = -0.5 * pow(eps, 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.00012d0)) .or. (.not. (eps <= 0.000135d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = (-0.5d0) * (eps ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.00012) || !(eps <= 0.000135)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = -0.5 * Math.pow(eps, 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00012) or not (eps <= 0.000135): tmp = -1.0 + math.cos(eps) else: tmp = -0.5 * math.pow(eps, 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00012) || !(eps <= 0.000135)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(-0.5 * (eps ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00012) || ~((eps <= 0.000135))) tmp = -1.0 + cos(eps); else tmp = -0.5 * (eps ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00012], N[Not[LessEqual[eps, 0.000135]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00012 \lor \neg \left(\varepsilon \leq 0.000135\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\end{array}
\end{array}
if eps < -1.20000000000000003e-4 or 1.35000000000000002e-4 < eps Initial program 54.5%
Taylor expanded in x around 0 54.6%
if -1.20000000000000003e-4 < eps < 1.35000000000000002e-4Initial program 25.0%
Taylor expanded in x around 0 25.1%
Taylor expanded in eps around 0 41.1%
Final simplification48.0%
(FPCore (x eps) :precision binary64 (+ -1.0 (cos eps)))
double code(double x, double eps) {
return -1.0 + cos(eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-1.0d0) + cos(eps)
end function
public static double code(double x, double eps) {
return -1.0 + Math.cos(eps);
}
def code(x, eps): return -1.0 + math.cos(eps)
function code(x, eps) return Float64(-1.0 + cos(eps)) end
function tmp = code(x, eps) tmp = -1.0 + cos(eps); end
code[x_, eps_] := N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \cos \varepsilon
\end{array}
Initial program 40.1%
Taylor expanded in x around 0 40.2%
Final simplification40.2%
(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 40.1%
Taylor expanded in x around 0 40.2%
Taylor expanded in eps around 0 13.6%
Final simplification13.6%
herbie shell --seed 2024018
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))