
(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 18 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (* (sin eps) (sin x))))
(if (<= eps -0.0056)
(- (* (cos x) t_0) (expm1 (log1p t_1)))
(if (<= eps 0.0049)
(-
(*
(cos x)
(+ (* -0.5 (pow eps 2.0)) (* 0.041666666666666664 (pow eps 4.0))))
t_1)
(fma t_0 (cos x) (* (sin eps) (- (sin x))))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = sin(eps) * sin(x);
double tmp;
if (eps <= -0.0056) {
tmp = (cos(x) * t_0) - expm1(log1p(t_1));
} else if (eps <= 0.0049) {
tmp = (cos(x) * ((-0.5 * pow(eps, 2.0)) + (0.041666666666666664 * pow(eps, 4.0)))) - t_1;
} else {
tmp = fma(t_0, cos(x), (sin(eps) * -sin(x)));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(sin(eps) * sin(x)) tmp = 0.0 if (eps <= -0.0056) tmp = Float64(Float64(cos(x) * t_0) - expm1(log1p(t_1))); elseif (eps <= 0.0049) tmp = Float64(Float64(cos(x) * Float64(Float64(-0.5 * (eps ^ 2.0)) + Float64(0.041666666666666664 * (eps ^ 4.0)))) - t_1); else tmp = fma(t_0, cos(x), Float64(sin(eps) * Float64(-sin(x)))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.0056], N[(N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision] - N[(Exp[N[Log[1 + t$95$1], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.0049], 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[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := \sin \varepsilon \cdot \sin x\\
\mathbf{if}\;\varepsilon \leq -0.0056:\\
\;\;\;\;\cos x \cdot t_0 - \mathsf{expm1}\left(\mathsf{log1p}\left(t_1\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.0049:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2} + 0.041666666666666664 \cdot {\varepsilon}^{4}\right) - t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\end{array}
\end{array}
if eps < -0.00559999999999999994Initial program 50.1%
sub-neg50.1%
cos-sum98.5%
associate-+l-98.6%
fma-neg98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.6%
associate--r+98.6%
*-lft-identity98.6%
distribute-rgt-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
Simplified98.7%
expm1-log1p-u98.8%
Applied egg-rr98.8%
if -0.00559999999999999994 < eps < 0.0048999999999999998Initial program 20.7%
sub-neg20.7%
cos-sum23.0%
associate-+l-23.0%
fma-neg23.0%
Applied egg-rr23.0%
Taylor expanded in x around inf 23.0%
associate--r+81.8%
*-lft-identity81.8%
distribute-rgt-out--81.8%
sub-neg81.8%
metadata-eval81.8%
+-commutative81.8%
*-commutative81.8%
Simplified81.8%
Taylor expanded in eps around 0 99.8%
if 0.0048999999999999998 < eps Initial program 47.6%
sub-neg47.6%
cos-sum98.5%
associate-+l-98.4%
fma-neg98.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 98.4%
associate--r+98.5%
*-lft-identity98.5%
distribute-rgt-out--98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
*-commutative98.5%
Simplified98.5%
log1p-expm1-u98.0%
Applied egg-rr98.0%
log1p-expm1-u98.5%
*-commutative98.5%
fma-neg98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
Applied egg-rr98.7%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (fma (* (pow (sin eps) 2.0) (cos x)) (/ 1.0 (- -1.0 (cos eps))) (* (sin eps) (- (sin x)))))
double code(double x, double eps) {
return fma((pow(sin(eps), 2.0) * cos(x)), (1.0 / (-1.0 - cos(eps))), (sin(eps) * -sin(x)));
}
function code(x, eps) return fma(Float64((sin(eps) ^ 2.0) * cos(x)), Float64(1.0 / Float64(-1.0 - cos(eps))), Float64(sin(eps) * Float64(-sin(x)))) end
code[x_, eps_] := N[(N[(N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(-1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left({\sin \varepsilon}^{2} \cdot \cos x, \frac{1}{-1 - \cos \varepsilon}, \sin \varepsilon \cdot \left(-\sin x\right)\right)
\end{array}
Initial program 35.4%
sub-neg35.4%
cos-sum62.5%
associate-+l-62.5%
fma-neg62.6%
Applied egg-rr62.6%
Taylor expanded in x around inf 62.5%
associate--r+90.6%
*-lft-identity90.6%
distribute-rgt-out--90.6%
sub-neg90.6%
metadata-eval90.6%
+-commutative90.6%
*-commutative90.6%
Simplified90.6%
+-commutative90.6%
*-commutative90.6%
+-commutative90.6%
flip-+90.0%
associate-*l/90.0%
metadata-eval90.0%
1-sub-cos98.7%
pow298.7%
Applied egg-rr98.7%
div-inv98.6%
fma-neg98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
Applied egg-rr98.7%
Final simplification98.7%
(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 35.4%
sub-neg35.4%
cos-sum62.5%
associate-+l-62.5%
fma-neg62.6%
Applied egg-rr62.6%
Taylor expanded in x around inf 62.5%
associate--r+90.6%
*-lft-identity90.6%
distribute-rgt-out--90.6%
sub-neg90.6%
metadata-eval90.6%
+-commutative90.6%
*-commutative90.6%
Simplified90.6%
+-commutative90.6%
*-commutative90.6%
+-commutative90.6%
flip-+90.0%
associate-*l/90.0%
metadata-eval90.0%
1-sub-cos98.7%
pow298.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (* (sin eps) (sin x))))
(if (<= eps -0.0056)
(- (* (cos x) t_0) t_1)
(if (<= eps 0.0049)
(-
(*
(cos x)
(+ (* -0.5 (pow eps 2.0)) (* 0.041666666666666664 (pow eps 4.0))))
t_1)
(fma t_0 (cos x) (* (sin eps) (- (sin x))))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = sin(eps) * sin(x);
double tmp;
if (eps <= -0.0056) {
tmp = (cos(x) * t_0) - t_1;
} else if (eps <= 0.0049) {
tmp = (cos(x) * ((-0.5 * pow(eps, 2.0)) + (0.041666666666666664 * pow(eps, 4.0)))) - t_1;
} else {
tmp = fma(t_0, cos(x), (sin(eps) * -sin(x)));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(sin(eps) * sin(x)) tmp = 0.0 if (eps <= -0.0056) tmp = Float64(Float64(cos(x) * t_0) - t_1); elseif (eps <= 0.0049) tmp = Float64(Float64(cos(x) * Float64(Float64(-0.5 * (eps ^ 2.0)) + Float64(0.041666666666666664 * (eps ^ 4.0)))) - t_1); else tmp = fma(t_0, cos(x), Float64(sin(eps) * Float64(-sin(x)))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.0056], N[(N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision] - t$95$1), $MachinePrecision], If[LessEqual[eps, 0.0049], 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[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := \sin \varepsilon \cdot \sin x\\
\mathbf{if}\;\varepsilon \leq -0.0056:\\
\;\;\;\;\cos x \cdot t_0 - t_1\\
\mathbf{elif}\;\varepsilon \leq 0.0049:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2} + 0.041666666666666664 \cdot {\varepsilon}^{4}\right) - t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\end{array}
\end{array}
if eps < -0.00559999999999999994Initial program 50.1%
sub-neg50.1%
cos-sum98.5%
associate-+l-98.6%
fma-neg98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.6%
associate--r+98.6%
*-lft-identity98.6%
distribute-rgt-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
Simplified98.7%
if -0.00559999999999999994 < eps < 0.0048999999999999998Initial program 20.7%
sub-neg20.7%
cos-sum23.0%
associate-+l-23.0%
fma-neg23.0%
Applied egg-rr23.0%
Taylor expanded in x around inf 23.0%
associate--r+81.8%
*-lft-identity81.8%
distribute-rgt-out--81.8%
sub-neg81.8%
metadata-eval81.8%
+-commutative81.8%
*-commutative81.8%
Simplified81.8%
Taylor expanded in eps around 0 99.8%
if 0.0048999999999999998 < eps Initial program 47.6%
sub-neg47.6%
cos-sum98.5%
associate-+l-98.4%
fma-neg98.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 98.4%
associate--r+98.5%
*-lft-identity98.5%
distribute-rgt-out--98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
*-commutative98.5%
Simplified98.5%
log1p-expm1-u98.0%
Applied egg-rr98.0%
log1p-expm1-u98.5%
*-commutative98.5%
fma-neg98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
Applied egg-rr98.7%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))))
(if (<= eps -0.00019)
(- (* (cos x) t_0) (* (sin eps) (sin x)))
(if (<= eps 0.00019)
(*
(+
(* (cos x) (* eps 0.5))
(* (sin x) (+ 1.0 (* (pow eps 2.0) -0.125))))
(* -2.0 (sin (* eps 0.5))))
(fma t_0 (cos x) (* (sin eps) (- (sin x))))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double tmp;
if (eps <= -0.00019) {
tmp = (cos(x) * t_0) - (sin(eps) * sin(x));
} else if (eps <= 0.00019) {
tmp = ((cos(x) * (eps * 0.5)) + (sin(x) * (1.0 + (pow(eps, 2.0) * -0.125)))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = fma(t_0, cos(x), (sin(eps) * -sin(x)));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) tmp = 0.0 if (eps <= -0.00019) tmp = Float64(Float64(cos(x) * t_0) - Float64(sin(eps) * sin(x))); elseif (eps <= 0.00019) tmp = Float64(Float64(Float64(cos(x) * Float64(eps * 0.5)) + Float64(sin(x) * Float64(1.0 + Float64((eps ^ 2.0) * -0.125)))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = fma(t_0, cos(x), Float64(sin(eps) * Float64(-sin(x)))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00019], N[(N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00019], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[(eps * 0.5), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(1.0 + N[(N[Power[eps, 2.0], $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Cos[x], $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}\;\varepsilon \leq -0.00019:\\
\;\;\;\;\cos x \cdot t_0 - \sin \varepsilon \cdot \sin x\\
\mathbf{elif}\;\varepsilon \leq 0.00019:\\
\;\;\;\;\left(\cos x \cdot \left(\varepsilon \cdot 0.5\right) + \sin x \cdot \left(1 + {\varepsilon}^{2} \cdot -0.125\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\end{array}
\end{array}
if eps < -1.9000000000000001e-4Initial program 50.1%
sub-neg50.1%
cos-sum98.5%
associate-+l-98.6%
fma-neg98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.6%
associate--r+98.6%
*-lft-identity98.6%
distribute-rgt-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
Simplified98.7%
if -1.9000000000000001e-4 < eps < 1.9000000000000001e-4Initial program 20.9%
diff-cos38.5%
div-inv38.5%
associate--l+38.5%
metadata-eval38.5%
div-inv38.5%
+-commutative38.5%
associate-+l+38.5%
metadata-eval38.5%
Applied egg-rr38.5%
associate-*r*38.5%
*-commutative38.5%
*-commutative38.5%
+-commutative38.5%
count-238.5%
fma-def38.5%
*-commutative38.5%
associate-+r-38.5%
+-commutative38.5%
associate--l+98.9%
+-inverses98.9%
Simplified98.9%
Taylor expanded in eps around 0 99.6%
associate-+r+99.6%
+-commutative99.6%
associate-*r*99.6%
*-lft-identity99.6%
associate-*r*99.6%
distribute-rgt-out99.6%
Simplified99.6%
if 1.9000000000000001e-4 < eps Initial program 47.0%
sub-neg47.0%
cos-sum98.3%
associate-+l-98.3%
fma-neg98.4%
Applied egg-rr98.4%
Taylor expanded in x around inf 98.3%
associate--r+98.4%
*-lft-identity98.4%
distribute-rgt-out--98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
*-commutative98.5%
Simplified98.5%
log1p-expm1-u98.0%
Applied egg-rr98.0%
log1p-expm1-u98.5%
*-commutative98.5%
fma-neg98.6%
*-commutative98.6%
distribute-rgt-neg-in98.6%
Applied egg-rr98.6%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00019) (not (<= eps 0.00019)))
(- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x)))
(*
(+ (* (cos x) (* eps 0.5)) (* (sin x) (+ 1.0 (* (pow eps 2.0) -0.125))))
(* -2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00019) || !(eps <= 0.00019)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = ((cos(x) * (eps * 0.5)) + (sin(x) * (1.0 + (pow(eps, 2.0) * -0.125)))) * (-2.0 * sin((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.00019d0))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = ((cos(x) * (eps * 0.5d0)) + (sin(x) * (1.0d0 + ((eps ** 2.0d0) * (-0.125d0))))) * ((-2.0d0) * sin((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.00019)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = ((Math.cos(x) * (eps * 0.5)) + (Math.sin(x) * (1.0 + (Math.pow(eps, 2.0) * -0.125)))) * (-2.0 * Math.sin((eps * 0.5)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00019) or not (eps <= 0.00019): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = ((math.cos(x) * (eps * 0.5)) + (math.sin(x) * (1.0 + (math.pow(eps, 2.0) * -0.125)))) * (-2.0 * math.sin((eps * 0.5))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00019) || !(eps <= 0.00019)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(Float64(cos(x) * Float64(eps * 0.5)) + Float64(sin(x) * Float64(1.0 + Float64((eps ^ 2.0) * -0.125)))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00019) || ~((eps <= 0.00019))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = ((cos(x) * (eps * 0.5)) + (sin(x) * (1.0 + ((eps ^ 2.0) * -0.125)))) * (-2.0 * sin((eps * 0.5))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00019], N[Not[LessEqual[eps, 0.00019]], $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[(N[Cos[x], $MachinePrecision] * N[(eps * 0.5), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(1.0 + N[(N[Power[eps, 2.0], $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-2.0 * N[Sin[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.00019\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(\cos x \cdot \left(\varepsilon \cdot 0.5\right) + \sin x \cdot \left(1 + {\varepsilon}^{2} \cdot -0.125\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -1.9000000000000001e-4 or 1.9000000000000001e-4 < eps Initial program 48.4%
sub-neg48.4%
cos-sum98.4%
associate-+l-98.4%
fma-neg98.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 98.4%
associate--r+98.5%
*-lft-identity98.5%
distribute-rgt-out--98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
*-commutative98.6%
Simplified98.6%
if -1.9000000000000001e-4 < eps < 1.9000000000000001e-4Initial program 20.9%
diff-cos38.5%
div-inv38.5%
associate--l+38.5%
metadata-eval38.5%
div-inv38.5%
+-commutative38.5%
associate-+l+38.5%
metadata-eval38.5%
Applied egg-rr38.5%
associate-*r*38.5%
*-commutative38.5%
*-commutative38.5%
+-commutative38.5%
count-238.5%
fma-def38.5%
*-commutative38.5%
associate-+r-38.5%
+-commutative38.5%
associate--l+98.9%
+-inverses98.9%
Simplified98.9%
Taylor expanded in eps around 0 99.6%
associate-+r+99.6%
+-commutative99.6%
associate-*r*99.6%
*-lft-identity99.6%
associate-*r*99.6%
distribute-rgt-out99.6%
Simplified99.6%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (sin eps) (sin x))))
(if (or (<= eps -0.000115) (not (<= eps 0.000125)))
(- (* (cos x) (+ -1.0 (cos eps))) t_0)
(- (* (cos x) (* -0.5 (pow eps 2.0))) t_0))))
double code(double x, double eps) {
double t_0 = sin(eps) * sin(x);
double tmp;
if ((eps <= -0.000115) || !(eps <= 0.000125)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - t_0;
} else {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - 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 = sin(eps) * sin(x)
if ((eps <= (-0.000115d0)) .or. (.not. (eps <= 0.000125d0))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - t_0
else
tmp = (cos(x) * ((-0.5d0) * (eps ** 2.0d0))) - t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin(eps) * Math.sin(x);
double tmp;
if ((eps <= -0.000115) || !(eps <= 0.000125)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - t_0;
} else {
tmp = (Math.cos(x) * (-0.5 * Math.pow(eps, 2.0))) - t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.sin(eps) * math.sin(x) tmp = 0 if (eps <= -0.000115) or not (eps <= 0.000125): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - t_0 else: tmp = (math.cos(x) * (-0.5 * math.pow(eps, 2.0))) - t_0 return tmp
function code(x, eps) t_0 = Float64(sin(eps) * sin(x)) tmp = 0.0 if ((eps <= -0.000115) || !(eps <= 0.000125)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - t_0); else tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - t_0); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin(eps) * sin(x); tmp = 0.0; if ((eps <= -0.000115) || ~((eps <= 0.000125))) tmp = (cos(x) * (-1.0 + cos(eps))) - t_0; else tmp = (cos(x) * (-0.5 * (eps ^ 2.0))) - t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[eps, -0.000115], N[Not[LessEqual[eps, 0.000125]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \varepsilon \cdot \sin x\\
\mathbf{if}\;\varepsilon \leq -0.000115 \lor \neg \left(\varepsilon \leq 0.000125\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - t_0\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - t_0\\
\end{array}
\end{array}
if eps < -1.15e-4 or 1.25e-4 < eps Initial program 48.4%
sub-neg48.4%
cos-sum98.4%
associate-+l-98.4%
fma-neg98.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 98.4%
associate--r+98.5%
*-lft-identity98.5%
distribute-rgt-out--98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
*-commutative98.6%
Simplified98.6%
if -1.15e-4 < eps < 1.25e-4Initial program 20.9%
sub-neg20.9%
cos-sum22.5%
associate-+l-22.5%
fma-neg22.5%
Applied egg-rr22.5%
Taylor expanded in x around inf 22.5%
associate--r+81.7%
*-lft-identity81.7%
distribute-rgt-out--81.7%
sub-neg81.7%
metadata-eval81.7%
+-commutative81.7%
*-commutative81.7%
Simplified81.7%
Taylor expanded in eps around 0 99.6%
associate-*r*99.6%
Simplified99.6%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.1e-5) (not (<= eps 4.5e-5))) (- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x))) (* (* -2.0 (sin (* eps 0.5))) (+ (sin x) (* 0.5 (* eps (cos x)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.1e-5) || !(eps <= 4.5e-5)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = (-2.0 * sin((eps * 0.5))) * (sin(x) + (0.5 * (eps * cos(x))));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.1d-5)) .or. (.not. (eps <= 4.5d-5))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = ((-2.0d0) * sin((eps * 0.5d0))) * (sin(x) + (0.5d0 * (eps * cos(x))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.1e-5) || !(eps <= 4.5e-5)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = (-2.0 * Math.sin((eps * 0.5))) * (Math.sin(x) + (0.5 * (eps * Math.cos(x))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.1e-5) or not (eps <= 4.5e-5): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = (-2.0 * math.sin((eps * 0.5))) * (math.sin(x) + (0.5 * (eps * math.cos(x)))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.1e-5) || !(eps <= 4.5e-5)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(-2.0 * sin(Float64(eps * 0.5))) * Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.1e-5) || ~((eps <= 4.5e-5))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = (-2.0 * sin((eps * 0.5))) * (sin(x) + (0.5 * (eps * cos(x)))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.1e-5], N[Not[LessEqual[eps, 4.5e-5]], $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[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.1 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 4.5 \cdot 10^{-5}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right)\\
\end{array}
\end{array}
if eps < -1.1e-5 or 4.50000000000000028e-5 < eps Initial program 48.1%
sub-neg48.1%
cos-sum98.3%
associate-+l-98.3%
fma-neg98.3%
Applied egg-rr98.3%
Taylor expanded in x around inf 98.3%
associate--r+98.4%
*-lft-identity98.4%
distribute-rgt-out--98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
*-commutative98.5%
Simplified98.5%
if -1.1e-5 < eps < 4.50000000000000028e-5Initial program 21.0%
diff-cos38.8%
div-inv38.8%
associate--l+38.8%
metadata-eval38.8%
div-inv38.8%
+-commutative38.8%
associate-+l+38.8%
metadata-eval38.8%
Applied egg-rr38.8%
associate-*r*38.8%
*-commutative38.8%
*-commutative38.8%
+-commutative38.8%
count-238.8%
fma-def38.8%
*-commutative38.8%
associate-+r-38.8%
+-commutative38.8%
associate--l+99.3%
+-inverses99.3%
Simplified99.3%
Taylor expanded in eps around 0 99.6%
Final simplification99.0%
(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 35.4%
diff-cos43.5%
div-inv43.5%
associate--l+43.5%
metadata-eval43.5%
div-inv43.5%
+-commutative43.5%
associate-+l+43.6%
metadata-eval43.6%
Applied egg-rr43.6%
associate-*r*43.6%
*-commutative43.6%
*-commutative43.6%
+-commutative43.6%
count-243.6%
fma-def43.6%
*-commutative43.6%
associate-+r-43.6%
+-commutative43.6%
associate--l+73.0%
+-inverses73.0%
Simplified73.0%
Final simplification73.0%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* eps 0.5)) (sin (* 0.5 (+ eps (* 2.0 x)))))))
double code(double x, double eps) {
return -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps + (2.0 * x)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((eps * 0.5d0)) * sin((0.5d0 * (eps + (2.0d0 * x)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((eps * 0.5)) * Math.sin((0.5 * (eps + (2.0 * x)))));
}
def code(x, eps): return -2.0 * (math.sin((eps * 0.5)) * math.sin((0.5 * (eps + (2.0 * x)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(eps * 0.5)) * sin(Float64(0.5 * Float64(eps + Float64(2.0 * x)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps + (2.0 * x))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(2.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + 2 \cdot x\right)\right)\right)
\end{array}
Initial program 35.4%
sub-neg35.4%
cos-sum62.5%
associate-+l-62.5%
fma-neg62.6%
Applied egg-rr62.6%
Taylor expanded in x around inf 62.5%
associate--r+90.6%
*-lft-identity90.6%
distribute-rgt-out--90.6%
sub-neg90.6%
metadata-eval90.6%
+-commutative90.6%
*-commutative90.6%
Simplified90.6%
cancel-sign-sub-inv90.6%
distribute-lft-in90.6%
associate-+l+62.5%
*-commutative62.5%
neg-mul-162.5%
fma-udef62.6%
+-commutative62.6%
sub-neg62.6%
distribute-lft-neg-out62.6%
fma-neg62.5%
cos-sum35.4%
diff-cos43.5%
Applied egg-rr73.0%
*-commutative73.0%
+-inverses73.0%
*-commutative73.0%
count-273.0%
Simplified73.0%
Final simplification73.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -1.75e-46) (not (<= x 0.37)))
(* (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 <= -1.75e-46) || !(x <= 0.37)) {
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 <= (-1.75d-46)) .or. (.not. (x <= 0.37d0))) 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 <= -1.75e-46) || !(x <= 0.37)) {
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 <= -1.75e-46) or not (x <= 0.37): 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 <= -1.75e-46) || !(x <= 0.37)) 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 <= -1.75e-46) || ~((x <= 0.37))) 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, -1.75e-46], N[Not[LessEqual[x, 0.37]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -1.75 \cdot 10^{-46} \lor \neg \left(x \leq 0.37\right):\\
\;\;\;\;\sin x \cdot \left(-2 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -1.7500000000000001e-46 or 0.37 < x Initial program 7.9%
diff-cos7.3%
div-inv7.3%
associate--l+7.3%
metadata-eval7.3%
div-inv7.3%
+-commutative7.3%
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%
*-commutative7.6%
associate-+r-7.6%
+-commutative7.6%
associate--l+55.4%
+-inverses55.4%
Simplified55.4%
Taylor expanded in eps around 0 54.2%
if -1.7500000000000001e-46 < x < 0.37Initial program 74.9%
diff-cos95.4%
div-inv95.4%
associate--l+95.4%
metadata-eval95.4%
div-inv95.4%
+-commutative95.4%
associate-+l+95.4%
metadata-eval95.4%
Applied egg-rr95.4%
associate-*r*95.4%
*-commutative95.4%
*-commutative95.4%
+-commutative95.4%
count-295.4%
fma-def95.4%
*-commutative95.4%
associate-+r-95.4%
+-commutative95.4%
associate--l+98.3%
+-inverses98.3%
Simplified98.3%
Taylor expanded in x around 0 95.2%
Final simplification71.0%
(FPCore (x eps) :precision binary64 (if (or (<= x -1.75e-46) (not (<= x 0.37))) (* eps (- (sin x))) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -1.75e-46) || !(x <= 0.37)) {
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 ((x <= (-1.75d-46)) .or. (.not. (x <= 0.37d0))) 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 ((x <= -1.75e-46) || !(x <= 0.37)) {
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 (x <= -1.75e-46) or not (x <= 0.37): 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 ((x <= -1.75e-46) || !(x <= 0.37)) 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 ((x <= -1.75e-46) || ~((x <= 0.37))) tmp = eps * -sin(x); else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -1.75e-46], N[Not[LessEqual[x, 0.37]], $MachinePrecision]], 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}\;x \leq -1.75 \cdot 10^{-46} \lor \neg \left(x \leq 0.37\right):\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if x < -1.7500000000000001e-46 or 0.37 < x Initial program 7.9%
Taylor expanded in eps around 0 51.3%
mul-1-neg51.3%
*-commutative51.3%
distribute-rgt-neg-in51.3%
Simplified51.3%
if -1.7500000000000001e-46 < x < 0.37Initial program 74.9%
diff-cos95.4%
div-inv95.4%
associate--l+95.4%
metadata-eval95.4%
div-inv95.4%
+-commutative95.4%
associate-+l+95.4%
metadata-eval95.4%
Applied egg-rr95.4%
associate-*r*95.4%
*-commutative95.4%
*-commutative95.4%
+-commutative95.4%
count-295.4%
fma-def95.4%
*-commutative95.4%
associate-+r-95.4%
+-commutative95.4%
associate--l+98.3%
+-inverses98.3%
Simplified98.3%
Taylor expanded in x around 0 95.2%
Final simplification69.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0082) (not (<= eps 7.5e-8))) (- (cos eps) (cos x)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0082) || !(eps <= 7.5e-8)) {
tmp = cos(eps) - cos(x);
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.0082d0)) .or. (.not. (eps <= 7.5d-8))) then
tmp = cos(eps) - cos(x)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0082) || !(eps <= 7.5e-8)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0082) or not (eps <= 7.5e-8): tmp = math.cos(eps) - math.cos(x) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0082) || !(eps <= 7.5e-8)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0082) || ~((eps <= 7.5e-8))) tmp = cos(eps) - cos(x); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0082], N[Not[LessEqual[eps, 7.5e-8]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0082 \lor \neg \left(\varepsilon \leq 7.5 \cdot 10^{-8}\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -0.00820000000000000069 or 7.4999999999999997e-8 < eps Initial program 48.6%
Taylor expanded in x around 0 51.5%
if -0.00820000000000000069 < eps < 7.4999999999999997e-8Initial program 20.6%
Taylor expanded in eps around 0 81.1%
mul-1-neg81.1%
*-commutative81.1%
distribute-rgt-neg-in81.1%
Simplified81.1%
Final simplification65.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (* -0.5 (pow eps 2.0))))
(if (<= eps -0.0082)
t_0
(if (<= eps 5.9e-269)
t_1
(if (<= eps 7.2e-140) (- (* eps x)) (if (<= eps 0.000125) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = -0.5 * pow(eps, 2.0);
double tmp;
if (eps <= -0.0082) {
tmp = t_0;
} else if (eps <= 5.9e-269) {
tmp = t_1;
} else if (eps <= 7.2e-140) {
tmp = -(eps * x);
} else if (eps <= 0.000125) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = (-1.0d0) + cos(eps)
t_1 = (-0.5d0) * (eps ** 2.0d0)
if (eps <= (-0.0082d0)) then
tmp = t_0
else if (eps <= 5.9d-269) then
tmp = t_1
else if (eps <= 7.2d-140) then
tmp = -(eps * x)
else if (eps <= 0.000125d0) then
tmp = t_1
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 t_1 = -0.5 * Math.pow(eps, 2.0);
double tmp;
if (eps <= -0.0082) {
tmp = t_0;
} else if (eps <= 5.9e-269) {
tmp = t_1;
} else if (eps <= 7.2e-140) {
tmp = -(eps * x);
} else if (eps <= 0.000125) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) t_1 = -0.5 * math.pow(eps, 2.0) tmp = 0 if eps <= -0.0082: tmp = t_0 elif eps <= 5.9e-269: tmp = t_1 elif eps <= 7.2e-140: tmp = -(eps * x) elif eps <= 0.000125: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(-0.5 * (eps ^ 2.0)) tmp = 0.0 if (eps <= -0.0082) tmp = t_0; elseif (eps <= 5.9e-269) tmp = t_1; elseif (eps <= 7.2e-140) tmp = Float64(-Float64(eps * x)); elseif (eps <= 0.000125) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = -1.0 + cos(eps); t_1 = -0.5 * (eps ^ 2.0); tmp = 0.0; if (eps <= -0.0082) tmp = t_0; elseif (eps <= 5.9e-269) tmp = t_1; elseif (eps <= 7.2e-140) tmp = -(eps * x); elseif (eps <= 0.000125) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.0082], t$95$0, If[LessEqual[eps, 5.9e-269], t$95$1, If[LessEqual[eps, 7.2e-140], (-N[(eps * x), $MachinePrecision]), If[LessEqual[eps, 0.000125], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := -0.5 \cdot {\varepsilon}^{2}\\
\mathbf{if}\;\varepsilon \leq -0.0082:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 5.9 \cdot 10^{-269}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 7.2 \cdot 10^{-140}:\\
\;\;\;\;-\varepsilon \cdot x\\
\mathbf{elif}\;\varepsilon \leq 0.000125:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -0.00820000000000000069 or 1.25e-4 < eps Initial program 48.7%
Taylor expanded in x around 0 49.7%
if -0.00820000000000000069 < eps < 5.9e-269 or 7.2000000000000001e-140 < eps < 1.25e-4Initial program 20.4%
Taylor expanded in x around 0 20.5%
Taylor expanded in eps around 0 41.4%
if 5.9e-269 < eps < 7.2000000000000001e-140Initial program 22.1%
Taylor expanded in eps around 0 22.1%
mul-1-neg22.1%
unsub-neg22.1%
Simplified22.1%
Taylor expanded in x around 0 49.8%
associate-*r*49.8%
mul-1-neg49.8%
Simplified49.8%
Final simplification46.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0082) (not (<= eps 0.00385))) (+ -1.0 (cos eps)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0082) || !(eps <= 0.00385)) {
tmp = -1.0 + cos(eps);
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.0082d0)) .or. (.not. (eps <= 0.00385d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0082) || !(eps <= 0.00385)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0082) or not (eps <= 0.00385): tmp = -1.0 + math.cos(eps) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0082) || !(eps <= 0.00385)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0082) || ~((eps <= 0.00385))) tmp = -1.0 + cos(eps); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0082], N[Not[LessEqual[eps, 0.00385]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0082 \lor \neg \left(\varepsilon \leq 0.00385\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -0.00820000000000000069 or 0.0038500000000000001 < eps Initial program 49.1%
Taylor expanded in x around 0 50.0%
if -0.00820000000000000069 < eps < 0.0038500000000000001Initial program 20.6%
Taylor expanded in eps around 0 80.0%
mul-1-neg80.0%
*-commutative80.0%
distribute-rgt-neg-in80.0%
Simplified80.0%
Final simplification64.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -7.4e-9) (not (<= eps 1.05e-8))) (+ -1.0 (cos eps)) (- (* eps x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -7.4e-9) || !(eps <= 1.05e-8)) {
tmp = -1.0 + cos(eps);
} else {
tmp = -(eps * x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-7.4d-9)) .or. (.not. (eps <= 1.05d-8))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = -(eps * x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -7.4e-9) || !(eps <= 1.05e-8)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = -(eps * x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -7.4e-9) or not (eps <= 1.05e-8): tmp = -1.0 + math.cos(eps) else: tmp = -(eps * x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -7.4e-9) || !(eps <= 1.05e-8)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(-Float64(eps * x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -7.4e-9) || ~((eps <= 1.05e-8))) tmp = -1.0 + cos(eps); else tmp = -(eps * x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -7.4e-9], N[Not[LessEqual[eps, 1.05e-8]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], (-N[(eps * x), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -7.4 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 1.05 \cdot 10^{-8}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-\varepsilon \cdot x\\
\end{array}
\end{array}
if eps < -7.4e-9 or 1.04999999999999997e-8 < eps Initial program 47.9%
Taylor expanded in x around 0 49.0%
if -7.4e-9 < eps < 1.04999999999999997e-8Initial program 20.7%
Taylor expanded in eps around 0 21.7%
mul-1-neg21.7%
unsub-neg21.7%
Simplified21.7%
Taylor expanded in x around 0 27.2%
associate-*r*27.2%
mul-1-neg27.2%
Simplified27.2%
Final simplification39.0%
(FPCore (x eps) :precision binary64 (- (* eps x)))
double code(double x, double eps) {
return -(eps * x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = -(eps * x)
end function
public static double code(double x, double eps) {
return -(eps * x);
}
def code(x, eps): return -(eps * x)
function code(x, eps) return Float64(-Float64(eps * x)) end
function tmp = code(x, eps) tmp = -(eps * x); end
code[x_, eps_] := (-N[(eps * x), $MachinePrecision])
\begin{array}{l}
\\
-\varepsilon \cdot x
\end{array}
Initial program 35.4%
Taylor expanded in eps around 0 12.2%
mul-1-neg12.2%
unsub-neg12.2%
Simplified12.2%
Taylor expanded in x around 0 14.2%
associate-*r*14.2%
mul-1-neg14.2%
Simplified14.2%
Final simplification14.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 35.4%
add-cube-cbrt35.2%
pow335.2%
Applied egg-rr35.2%
Taylor expanded in eps around 0 11.2%
pow-base-111.2%
*-lft-identity11.2%
+-inverses11.2%
Simplified11.2%
Final simplification11.2%
herbie shell --seed 2024010
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))