
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (sin eps) (sin x))))
(if (<= eps -0.0058)
(- (- (* (cos x) (cos eps)) t_0) (cos x))
(if (<= eps 0.0042)
(-
(*
(cos x)
(+ (* -0.5 (pow eps 2.0)) (* 0.041666666666666664 (pow eps 4.0))))
t_0)
(fma (+ -1.0 (cos eps)) (cos x) (* (sin x) (- (sin eps))))))))
double code(double x, double eps) {
double t_0 = sin(eps) * sin(x);
double tmp;
if (eps <= -0.0058) {
tmp = ((cos(x) * cos(eps)) - t_0) - cos(x);
} else if (eps <= 0.0042) {
tmp = (cos(x) * ((-0.5 * pow(eps, 2.0)) + (0.041666666666666664 * pow(eps, 4.0)))) - t_0;
} else {
tmp = fma((-1.0 + cos(eps)), cos(x), (sin(x) * -sin(eps)));
}
return tmp;
}
function code(x, eps) t_0 = Float64(sin(eps) * sin(x)) tmp = 0.0 if (eps <= -0.0058) tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - t_0) - cos(x)); elseif (eps <= 0.0042) tmp = Float64(Float64(cos(x) * Float64(Float64(-0.5 * (eps ^ 2.0)) + Float64(0.041666666666666664 * (eps ^ 4.0)))) - t_0); else tmp = fma(Float64(-1.0 + cos(eps)), cos(x), Float64(sin(x) * Float64(-sin(eps)))); 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.0058], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.0042], 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[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \varepsilon \cdot \sin x\\
\mathbf{if}\;\varepsilon \leq -0.0058:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - t_0\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 0.0042:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2} + 0.041666666666666664 \cdot {\varepsilon}^{4}\right) - t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1 + \cos \varepsilon, \cos x, \sin x \cdot \left(-\sin \varepsilon\right)\right)\\
\end{array}
\end{array}
if eps < -0.0058Initial program 59.2%
cos-sum98.3%
Applied egg-rr98.3%
if -0.0058 < eps < 0.00419999999999999974Initial program 17.1%
sub-neg17.1%
cos-sum18.7%
associate-+l-18.7%
fma-neg18.7%
Applied egg-rr18.7%
Taylor expanded in x around inf 18.7%
associate--r+83.1%
*-commutative83.1%
*-rgt-identity83.1%
distribute-lft-out--83.1%
sub-neg83.1%
metadata-eval83.1%
+-commutative83.1%
*-commutative83.1%
Simplified83.1%
Taylor expanded in eps around 0 99.7%
if 0.00419999999999999974 < eps Initial program 58.0%
sub-neg58.0%
cos-sum98.9%
associate-+l-98.9%
fma-neg99.0%
Applied egg-rr99.0%
Taylor expanded in x around inf 98.9%
associate--r+98.8%
*-commutative98.8%
*-rgt-identity98.8%
distribute-lft-out--98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
*-commutative98.9%
Simplified98.9%
+-commutative98.9%
*-commutative98.9%
fma-neg99.0%
+-commutative99.0%
distribute-rgt-neg-in99.0%
Applied egg-rr99.0%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (- (/ (* (pow (sin eps) 2.0) (cos x)) (- -1.0 (cos eps))) (expm1 (log1p (* (sin eps) (sin x))))))
double code(double x, double eps) {
return ((pow(sin(eps), 2.0) * cos(x)) / (-1.0 - cos(eps))) - expm1(log1p((sin(eps) * sin(x))));
}
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.expm1(Math.log1p((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.expm1(math.log1p((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))) - expm1(log1p(Float64(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[(Exp[N[Log[1 + N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\sin \varepsilon}^{2} \cdot \cos x}{-1 - \cos \varepsilon} - \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \varepsilon \cdot \sin x\right)\right)
\end{array}
Initial program 38.4%
sub-neg38.4%
cos-sum59.6%
associate-+l-59.6%
fma-neg59.6%
Applied egg-rr59.6%
Taylor expanded in x around inf 59.6%
associate--r+91.0%
*-commutative91.0%
*-rgt-identity91.0%
distribute-lft-out--91.0%
sub-neg91.0%
metadata-eval91.0%
+-commutative91.0%
*-commutative91.0%
Simplified91.0%
+-commutative91.0%
*-commutative91.0%
+-commutative91.0%
flip-+90.6%
associate-*l/90.6%
metadata-eval90.6%
1-sub-cos98.8%
pow298.8%
Applied egg-rr98.8%
expm1-log1p-u98.8%
*-commutative98.8%
Applied egg-rr98.8%
Final simplification98.8%
(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 38.4%
sub-neg38.4%
cos-sum59.6%
associate-+l-59.6%
fma-neg59.6%
Applied egg-rr59.6%
Taylor expanded in x around inf 59.6%
associate--r+91.0%
*-commutative91.0%
*-rgt-identity91.0%
distribute-lft-out--91.0%
sub-neg91.0%
metadata-eval91.0%
+-commutative91.0%
*-commutative91.0%
Simplified91.0%
+-commutative91.0%
*-commutative91.0%
+-commutative91.0%
flip-+90.6%
associate-*l/90.6%
metadata-eval90.6%
1-sub-cos98.8%
pow298.8%
Applied egg-rr98.8%
Final simplification98.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -4e-8) (not (<= x 2.15e-6)))
(fma (+ -1.0 (cos eps)) (cos x) (* (sin x) (- (sin eps))))
(*
(+ (* (+ (* -0.5 (pow x 2.0)) 1.0) t_0) (* x (cos (* eps 0.5))))
(* t_0 -2.0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -4e-8) || !(x <= 2.15e-6)) {
tmp = fma((-1.0 + cos(eps)), cos(x), (sin(x) * -sin(eps)));
} else {
tmp = ((((-0.5 * pow(x, 2.0)) + 1.0) * t_0) + (x * cos((eps * 0.5)))) * (t_0 * -2.0);
}
return tmp;
}
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -4e-8) || !(x <= 2.15e-6)) tmp = fma(Float64(-1.0 + cos(eps)), cos(x), Float64(sin(x) * Float64(-sin(eps)))); else tmp = Float64(Float64(Float64(Float64(Float64(-0.5 * (x ^ 2.0)) + 1.0) * t_0) + Float64(x * cos(Float64(eps * 0.5)))) * Float64(t_0 * -2.0)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -4e-8], N[Not[LessEqual[x, 2.15e-6]], $MachinePrecision]], N[(N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(-0.5 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision] + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(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 -4 \cdot 10^{-8} \lor \neg \left(x \leq 2.15 \cdot 10^{-6}\right):\\
\;\;\;\;\mathsf{fma}\left(-1 + \cos \varepsilon, \cos x, \sin x \cdot \left(-\sin \varepsilon\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-0.5 \cdot {x}^{2} + 1\right) \cdot t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(t_0 \cdot -2\right)\\
\end{array}
\end{array}
if x < -4.0000000000000001e-8 or 2.15000000000000017e-6 < x Initial program 8.5%
sub-neg8.5%
cos-sum51.4%
associate-+l-51.4%
fma-neg51.4%
Applied egg-rr51.4%
Taylor expanded in x around inf 51.4%
associate--r+98.6%
*-commutative98.6%
*-rgt-identity98.6%
distribute-lft-out--98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
*-commutative98.6%
Simplified98.6%
+-commutative98.6%
*-commutative98.6%
fma-neg98.7%
+-commutative98.7%
distribute-rgt-neg-in98.7%
Applied egg-rr98.7%
if -4.0000000000000001e-8 < x < 2.15000000000000017e-6Initial program 66.5%
diff-cos82.3%
div-inv82.3%
associate--l+82.3%
metadata-eval82.3%
div-inv82.3%
+-commutative82.3%
associate-+l+82.3%
metadata-eval82.3%
Applied egg-rr82.3%
associate-*r*82.3%
*-commutative82.3%
*-commutative82.3%
+-commutative82.3%
count-282.3%
fma-def82.3%
sub-neg82.3%
mul-1-neg82.3%
+-commutative82.3%
associate-+r+98.7%
mul-1-neg98.7%
sub-neg98.7%
+-inverses98.7%
remove-double-neg98.7%
mul-1-neg98.7%
sub-neg98.7%
neg-sub098.7%
mul-1-neg98.7%
remove-double-neg98.7%
Simplified98.7%
Taylor expanded in x around 0 99.5%
associate-+r+99.5%
associate-*r*99.5%
distribute-rgt1-in99.5%
Simplified99.5%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -2.6e-8) (not (<= x 2.15e-6)))
(- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x)))
(*
(+ (* (+ (* -0.5 (pow x 2.0)) 1.0) t_0) (* x (cos (* eps 0.5))))
(* t_0 -2.0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -2.6e-8) || !(x <= 2.15e-6)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = ((((-0.5 * pow(x, 2.0)) + 1.0) * t_0) + (x * cos((eps * 0.5)))) * (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 <= (-2.6d-8)) .or. (.not. (x <= 2.15d-6))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = (((((-0.5d0) * (x ** 2.0d0)) + 1.0d0) * t_0) + (x * cos((eps * 0.5d0)))) * (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 <= -2.6e-8) || !(x <= 2.15e-6)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = ((((-0.5 * Math.pow(x, 2.0)) + 1.0) * t_0) + (x * Math.cos((eps * 0.5)))) * (t_0 * -2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -2.6e-8) or not (x <= 2.15e-6): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = ((((-0.5 * math.pow(x, 2.0)) + 1.0) * t_0) + (x * math.cos((eps * 0.5)))) * (t_0 * -2.0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -2.6e-8) || !(x <= 2.15e-6)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(Float64(Float64(Float64(-0.5 * (x ^ 2.0)) + 1.0) * t_0) + Float64(x * cos(Float64(eps * 0.5)))) * Float64(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 <= -2.6e-8) || ~((x <= 2.15e-6))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = ((((-0.5 * (x ^ 2.0)) + 1.0) * t_0) + (x * cos((eps * 0.5)))) * (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, -2.6e-8], N[Not[LessEqual[x, 2.15e-6]], $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[(N[(-0.5 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision] + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(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 -2.6 \cdot 10^{-8} \lor \neg \left(x \leq 2.15 \cdot 10^{-6}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-0.5 \cdot {x}^{2} + 1\right) \cdot t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(t_0 \cdot -2\right)\\
\end{array}
\end{array}
if x < -2.6000000000000001e-8 or 2.15000000000000017e-6 < x Initial program 8.5%
sub-neg8.5%
cos-sum51.4%
associate-+l-51.4%
fma-neg51.4%
Applied egg-rr51.4%
Taylor expanded in x around inf 51.4%
associate--r+98.6%
*-commutative98.6%
*-rgt-identity98.6%
distribute-lft-out--98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
*-commutative98.6%
Simplified98.6%
if -2.6000000000000001e-8 < x < 2.15000000000000017e-6Initial program 66.5%
diff-cos82.3%
div-inv82.3%
associate--l+82.3%
metadata-eval82.3%
div-inv82.3%
+-commutative82.3%
associate-+l+82.3%
metadata-eval82.3%
Applied egg-rr82.3%
associate-*r*82.3%
*-commutative82.3%
*-commutative82.3%
+-commutative82.3%
count-282.3%
fma-def82.3%
sub-neg82.3%
mul-1-neg82.3%
+-commutative82.3%
associate-+r+98.7%
mul-1-neg98.7%
sub-neg98.7%
+-inverses98.7%
remove-double-neg98.7%
mul-1-neg98.7%
sub-neg98.7%
neg-sub098.7%
mul-1-neg98.7%
remove-double-neg98.7%
Simplified98.7%
Taylor expanded in x around 0 99.5%
associate-+r+99.5%
associate-*r*99.5%
distribute-rgt1-in99.5%
Simplified99.5%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -2.4e-8) (not (<= x 9.5e-39)))
(- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x)))
(* (* t_0 -2.0) (+ t_0 (* x (cos (* eps 0.5))))))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -2.4e-8) || !(x <= 9.5e-39)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = (t_0 * -2.0) * (t_0 + (x * cos((eps * 0.5))));
}
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 <= (-2.4d-8)) .or. (.not. (x <= 9.5d-39))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = (t_0 * (-2.0d0)) * (t_0 + (x * cos((eps * 0.5d0))))
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 <= -2.4e-8) || !(x <= 9.5e-39)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = (t_0 * -2.0) * (t_0 + (x * Math.cos((eps * 0.5))));
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -2.4e-8) or not (x <= 9.5e-39): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = (t_0 * -2.0) * (t_0 + (x * math.cos((eps * 0.5)))) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -2.4e-8) || !(x <= 9.5e-39)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(t_0 * -2.0) * Float64(t_0 + Float64(x * cos(Float64(eps * 0.5))))); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -2.4e-8) || ~((x <= 9.5e-39))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = (t_0 * -2.0) * (t_0 + (x * cos((eps * 0.5)))); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -2.4e-8], N[Not[LessEqual[x, 9.5e-39]], $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[(t$95$0 * -2.0), $MachinePrecision] * N[(t$95$0 + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -2.4 \cdot 10^{-8} \lor \neg \left(x \leq 9.5 \cdot 10^{-39}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(t_0 \cdot -2\right) \cdot \left(t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if x < -2.39999999999999998e-8 or 9.4999999999999999e-39 < x Initial program 12.0%
sub-neg12.0%
cos-sum52.9%
associate-+l-52.9%
fma-neg52.9%
Applied egg-rr52.9%
Taylor expanded in x around inf 52.9%
associate--r+98.6%
*-commutative98.6%
*-rgt-identity98.6%
distribute-lft-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
Simplified98.7%
if -2.39999999999999998e-8 < x < 9.4999999999999999e-39Initial program 66.5%
diff-cos83.3%
div-inv83.3%
associate--l+83.3%
metadata-eval83.3%
div-inv83.3%
+-commutative83.3%
associate-+l+83.3%
metadata-eval83.3%
Applied egg-rr83.3%
associate-*r*83.3%
*-commutative83.3%
*-commutative83.3%
+-commutative83.3%
count-283.3%
fma-def83.3%
sub-neg83.3%
mul-1-neg83.3%
+-commutative83.3%
associate-+r+99.2%
mul-1-neg99.2%
sub-neg99.2%
+-inverses99.2%
remove-double-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
neg-sub099.2%
mul-1-neg99.2%
remove-double-neg99.2%
Simplified99.2%
Taylor expanded in x around 0 99.5%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (<= (- (cos (+ eps x)) (cos x)) -0.0002)
(* -2.0 (pow t_0 2.0))
(* (sin x) (* t_0 -2.0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((cos((eps + x)) - cos(x)) <= -0.0002) {
tmp = -2.0 * pow(t_0, 2.0);
} else {
tmp = sin(x) * (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 ((cos((eps + x)) - cos(x)) <= (-0.0002d0)) then
tmp = (-2.0d0) * (t_0 ** 2.0d0)
else
tmp = sin(x) * (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 ((Math.cos((eps + x)) - Math.cos(x)) <= -0.0002) {
tmp = -2.0 * Math.pow(t_0, 2.0);
} else {
tmp = Math.sin(x) * (t_0 * -2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -0.0002: tmp = -2.0 * math.pow(t_0, 2.0) else: tmp = math.sin(x) * (t_0 * -2.0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -0.0002) tmp = Float64(-2.0 * (t_0 ^ 2.0)); else tmp = Float64(sin(x) * Float64(t_0 * -2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -0.0002) tmp = -2.0 * (t_0 ^ 2.0); else tmp = sin(x) * (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[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -0.0002], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * N[(t$95$0 * -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -0.0002:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(t_0 \cdot -2\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -2.0000000000000001e-4Initial program 79.2%
diff-cos79.8%
div-inv79.8%
associate--l+79.8%
metadata-eval79.8%
div-inv79.8%
+-commutative79.8%
associate-+l+79.9%
metadata-eval79.9%
Applied egg-rr79.9%
associate-*r*79.9%
*-commutative79.9%
*-commutative79.9%
+-commutative79.9%
count-279.9%
fma-def79.9%
sub-neg79.9%
mul-1-neg79.9%
+-commutative79.9%
associate-+r+80.0%
mul-1-neg80.0%
sub-neg80.0%
+-inverses80.0%
remove-double-neg80.0%
mul-1-neg80.0%
sub-neg80.0%
neg-sub080.0%
mul-1-neg80.0%
remove-double-neg80.0%
Simplified80.0%
Taylor expanded in x around 0 79.9%
if -2.0000000000000001e-4 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 15.1%
diff-cos26.6%
div-inv26.6%
associate--l+26.6%
metadata-eval26.6%
div-inv26.6%
+-commutative26.6%
associate-+l+26.6%
metadata-eval26.6%
Applied egg-rr26.6%
associate-*r*26.6%
*-commutative26.6%
*-commutative26.6%
+-commutative26.6%
count-226.6%
fma-def26.6%
sub-neg26.6%
mul-1-neg26.6%
+-commutative26.6%
associate-+r+77.6%
mul-1-neg77.6%
sub-neg77.6%
+-inverses77.6%
remove-double-neg77.6%
mul-1-neg77.6%
sub-neg77.6%
neg-sub077.6%
mul-1-neg77.6%
remove-double-neg77.6%
Simplified77.6%
Taylor expanded in eps around 0 65.2%
Final simplification70.5%
(FPCore (x eps) :precision binary64 (* (* (sin (* eps 0.5)) -2.0) (sin (* 0.5 (fma 2.0 x eps)))))
double code(double x, double eps) {
return (sin((eps * 0.5)) * -2.0) * sin((0.5 * fma(2.0, x, eps)));
}
function code(x, eps) return Float64(Float64(sin(Float64(eps * 0.5)) * -2.0) * sin(Float64(0.5 * fma(2.0, x, eps)))) end
code[x_, eps_] := N[(N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * -2.0), $MachinePrecision] * N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\sin \left(\varepsilon \cdot 0.5\right) \cdot -2\right) \cdot \sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right)
\end{array}
Initial program 38.4%
diff-cos45.9%
div-inv45.9%
associate--l+45.9%
metadata-eval45.9%
div-inv45.9%
+-commutative45.9%
associate-+l+46.0%
metadata-eval46.0%
Applied egg-rr46.0%
associate-*r*46.0%
*-commutative46.0%
*-commutative46.0%
+-commutative46.0%
count-246.0%
fma-def46.0%
sub-neg46.0%
mul-1-neg46.0%
+-commutative46.0%
associate-+r+78.5%
mul-1-neg78.5%
sub-neg78.5%
+-inverses78.5%
remove-double-neg78.5%
mul-1-neg78.5%
sub-neg78.5%
neg-sub078.5%
mul-1-neg78.5%
remove-double-neg78.5%
Simplified78.5%
Final simplification78.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (+ -1.0 (cos eps)) (* (sin eps) x)))
(t_1 (sin (* eps 0.5)))
(t_2 (* (sin x) (* t_1 -2.0))))
(if (<= x -0.0008)
t_2
(if (<= x -5.8e-58)
t_0
(if (<= x 3.8e-119)
(* -2.0 (pow t_1 2.0))
(if (<= x 0.00072) t_0 t_2))))))
double code(double x, double eps) {
double t_0 = (-1.0 + cos(eps)) - (sin(eps) * x);
double t_1 = sin((eps * 0.5));
double t_2 = sin(x) * (t_1 * -2.0);
double tmp;
if (x <= -0.0008) {
tmp = t_2;
} else if (x <= -5.8e-58) {
tmp = t_0;
} else if (x <= 3.8e-119) {
tmp = -2.0 * pow(t_1, 2.0);
} else if (x <= 0.00072) {
tmp = t_0;
} else {
tmp = t_2;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = ((-1.0d0) + cos(eps)) - (sin(eps) * x)
t_1 = sin((eps * 0.5d0))
t_2 = sin(x) * (t_1 * (-2.0d0))
if (x <= (-0.0008d0)) then
tmp = t_2
else if (x <= (-5.8d-58)) then
tmp = t_0
else if (x <= 3.8d-119) then
tmp = (-2.0d0) * (t_1 ** 2.0d0)
else if (x <= 0.00072d0) then
tmp = t_0
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = (-1.0 + Math.cos(eps)) - (Math.sin(eps) * x);
double t_1 = Math.sin((eps * 0.5));
double t_2 = Math.sin(x) * (t_1 * -2.0);
double tmp;
if (x <= -0.0008) {
tmp = t_2;
} else if (x <= -5.8e-58) {
tmp = t_0;
} else if (x <= 3.8e-119) {
tmp = -2.0 * Math.pow(t_1, 2.0);
} else if (x <= 0.00072) {
tmp = t_0;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, eps): t_0 = (-1.0 + math.cos(eps)) - (math.sin(eps) * x) t_1 = math.sin((eps * 0.5)) t_2 = math.sin(x) * (t_1 * -2.0) tmp = 0 if x <= -0.0008: tmp = t_2 elif x <= -5.8e-58: tmp = t_0 elif x <= 3.8e-119: tmp = -2.0 * math.pow(t_1, 2.0) elif x <= 0.00072: tmp = t_0 else: tmp = t_2 return tmp
function code(x, eps) t_0 = Float64(Float64(-1.0 + cos(eps)) - Float64(sin(eps) * x)) t_1 = sin(Float64(eps * 0.5)) t_2 = Float64(sin(x) * Float64(t_1 * -2.0)) tmp = 0.0 if (x <= -0.0008) tmp = t_2; elseif (x <= -5.8e-58) tmp = t_0; elseif (x <= 3.8e-119) tmp = Float64(-2.0 * (t_1 ^ 2.0)); elseif (x <= 0.00072) tmp = t_0; else tmp = t_2; end return tmp end
function tmp_2 = code(x, eps) t_0 = (-1.0 + cos(eps)) - (sin(eps) * x); t_1 = sin((eps * 0.5)); t_2 = sin(x) * (t_1 * -2.0); tmp = 0.0; if (x <= -0.0008) tmp = t_2; elseif (x <= -5.8e-58) tmp = t_0; elseif (x <= 3.8e-119) tmp = -2.0 * (t_1 ^ 2.0); elseif (x <= 0.00072) tmp = t_0; else tmp = t_2; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[x], $MachinePrecision] * N[(t$95$1 * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0008], t$95$2, If[LessEqual[x, -5.8e-58], t$95$0, If[LessEqual[x, 3.8e-119], N[(-2.0 * N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.00072], t$95$0, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot x\\
t_1 := \sin \left(\varepsilon \cdot 0.5\right)\\
t_2 := \sin x \cdot \left(t_1 \cdot -2\right)\\
\mathbf{if}\;x \leq -0.0008:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq -5.8 \cdot 10^{-58}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{-119}:\\
\;\;\;\;-2 \cdot {t_1}^{2}\\
\mathbf{elif}\;x \leq 0.00072:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if x < -8.00000000000000038e-4 or 7.20000000000000045e-4 < x Initial program 8.5%
diff-cos7.3%
div-inv7.3%
associate--l+7.3%
metadata-eval7.3%
div-inv7.3%
+-commutative7.3%
associate-+l+7.4%
metadata-eval7.4%
Applied egg-rr7.4%
associate-*r*7.4%
*-commutative7.4%
*-commutative7.4%
+-commutative7.4%
count-27.4%
fma-def7.4%
sub-neg7.4%
mul-1-neg7.4%
+-commutative7.4%
associate-+r+56.9%
mul-1-neg56.9%
sub-neg56.9%
+-inverses56.9%
remove-double-neg56.9%
mul-1-neg56.9%
sub-neg56.9%
neg-sub056.9%
mul-1-neg56.9%
remove-double-neg56.9%
Simplified56.9%
Taylor expanded in eps around 0 56.6%
if -8.00000000000000038e-4 < x < -5.7999999999999998e-58 or 3.79999999999999975e-119 < x < 7.20000000000000045e-4Initial program 52.2%
Taylor expanded in x around 0 54.3%
sub-neg54.3%
metadata-eval54.3%
+-commutative54.3%
associate-+r+93.4%
+-commutative93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
unpow293.4%
associate-*l*93.4%
distribute-lft-out--93.4%
+-commutative93.4%
*-commutative93.4%
fma-def93.4%
Simplified93.4%
Taylor expanded in x around 0 93.0%
mul-1-neg93.0%
distribute-rgt-neg-out93.0%
Simplified93.0%
if -5.7999999999999998e-58 < x < 3.79999999999999975e-119Initial program 75.7%
diff-cos97.5%
div-inv97.5%
associate--l+97.5%
metadata-eval97.5%
div-inv97.5%
+-commutative97.5%
associate-+l+97.5%
metadata-eval97.5%
Applied egg-rr97.5%
associate-*r*97.5%
*-commutative97.5%
*-commutative97.5%
+-commutative97.5%
count-297.5%
fma-def97.5%
sub-neg97.5%
mul-1-neg97.5%
+-commutative97.5%
associate-+r+99.4%
mul-1-neg99.4%
sub-neg99.4%
+-inverses99.4%
remove-double-neg99.4%
mul-1-neg99.4%
sub-neg99.4%
neg-sub099.4%
mul-1-neg99.4%
remove-double-neg99.4%
Simplified99.4%
Taylor expanded in x around 0 97.6%
Final simplification76.8%
(FPCore (x eps) :precision binary64 (* (sin (* eps 0.5)) (* -2.0 (sin (* 0.5 (+ x (+ eps x)))))))
double code(double x, double eps) {
return sin((eps * 0.5)) * (-2.0 * sin((0.5 * (x + (eps + x)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin((eps * 0.5d0)) * ((-2.0d0) * sin((0.5d0 * (x + (eps + x)))))
end function
public static double code(double x, double eps) {
return Math.sin((eps * 0.5)) * (-2.0 * Math.sin((0.5 * (x + (eps + x)))));
}
def code(x, eps): return math.sin((eps * 0.5)) * (-2.0 * math.sin((0.5 * (x + (eps + x)))))
function code(x, eps) return Float64(sin(Float64(eps * 0.5)) * Float64(-2.0 * sin(Float64(0.5 * Float64(x + Float64(eps + x)))))) end
function tmp = code(x, eps) tmp = sin((eps * 0.5)) * (-2.0 * sin((0.5 * (x + (eps + x))))); end
code[x_, eps_] := N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[Sin[N[(0.5 * N[(x + N[(eps + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(\varepsilon \cdot 0.5\right) \cdot \left(-2 \cdot \sin \left(0.5 \cdot \left(x + \left(\varepsilon + x\right)\right)\right)\right)
\end{array}
Initial program 38.4%
sub-neg38.4%
cos-sum59.6%
associate-+l-59.6%
fma-neg59.6%
Applied egg-rr59.6%
Taylor expanded in x around inf 59.6%
associate--r+91.0%
*-commutative91.0%
*-rgt-identity91.0%
distribute-lft-out--91.0%
sub-neg91.0%
metadata-eval91.0%
+-commutative91.0%
*-commutative91.0%
Simplified91.0%
distribute-lft-in91.0%
associate--l+59.6%
*-commutative59.6%
neg-mul-159.6%
cos-sum38.4%
+-commutative38.4%
sub-neg38.4%
diff-cos45.9%
div-inv45.9%
+-commutative45.9%
associate--l+78.4%
metadata-eval78.4%
div-inv78.4%
associate-+l+78.4%
metadata-eval78.4%
Applied egg-rr78.4%
*-commutative78.4%
associate-*l*78.4%
+-inverses78.4%
+-rgt-identity78.4%
*-commutative78.4%
Simplified78.4%
Final simplification78.4%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.00023)
(- (cos eps) (cos x))
(if (<= eps 3.3e-19)
(* eps (- (sin x)))
(* -2.0 (pow (sin (* eps 0.5)) 2.0)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.00023) {
tmp = cos(eps) - cos(x);
} else if (eps <= 3.3e-19) {
tmp = eps * -sin(x);
} else {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-0.00023d0)) then
tmp = cos(eps) - cos(x)
else if (eps <= 3.3d-19) then
tmp = eps * -sin(x)
else
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -0.00023) {
tmp = Math.cos(eps) - Math.cos(x);
} else if (eps <= 3.3e-19) {
tmp = eps * -Math.sin(x);
} else {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.00023: tmp = math.cos(eps) - math.cos(x) elif eps <= 3.3e-19: tmp = eps * -math.sin(x) else: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.00023) tmp = Float64(cos(eps) - cos(x)); elseif (eps <= 3.3e-19) tmp = Float64(eps * Float64(-sin(x))); else tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -0.00023) tmp = cos(eps) - cos(x); elseif (eps <= 3.3e-19) tmp = eps * -sin(x); else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.00023], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.3e-19], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00023:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{elif}\;\varepsilon \leq 3.3 \cdot 10^{-19}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if eps < -2.3000000000000001e-4Initial program 59.2%
Taylor expanded in x around 0 61.0%
if -2.3000000000000001e-4 < eps < 3.2999999999999998e-19Initial program 16.9%
Taylor expanded in eps around 0 84.0%
mul-1-neg84.0%
*-commutative84.0%
distribute-rgt-neg-in84.0%
Simplified84.0%
if 3.2999999999999998e-19 < eps Initial program 56.0%
diff-cos58.7%
div-inv58.7%
associate--l+58.7%
metadata-eval58.7%
div-inv58.7%
+-commutative58.7%
associate-+l+58.6%
metadata-eval58.6%
Applied egg-rr58.6%
associate-*r*58.6%
*-commutative58.6%
*-commutative58.6%
+-commutative58.6%
count-258.6%
fma-def58.6%
sub-neg58.6%
mul-1-neg58.6%
+-commutative58.6%
associate-+r+61.2%
mul-1-neg61.2%
sub-neg61.2%
+-inverses61.2%
remove-double-neg61.2%
mul-1-neg61.2%
sub-neg61.2%
neg-sub061.2%
mul-1-neg61.2%
remove-double-neg61.2%
Simplified61.2%
Taylor expanded in x around 0 58.9%
Final simplification71.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000185) (not (<= eps 0.0024))) (- (cos eps) (cos x)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000185) || !(eps <= 0.0024)) {
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.000185d0)) .or. (.not. (eps <= 0.0024d0))) 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.000185) || !(eps <= 0.0024)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000185) or not (eps <= 0.0024): 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.000185) || !(eps <= 0.0024)) 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.000185) || ~((eps <= 0.0024))) tmp = cos(eps) - cos(x); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000185], N[Not[LessEqual[eps, 0.0024]], $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.000185 \lor \neg \left(\varepsilon \leq 0.0024\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -1.85e-4 or 0.00239999999999999979 < eps Initial program 58.7%
Taylor expanded in x around 0 60.6%
if -1.85e-4 < eps < 0.00239999999999999979Initial program 17.1%
Taylor expanded in eps around 0 82.3%
mul-1-neg82.3%
*-commutative82.3%
distribute-rgt-neg-in82.3%
Simplified82.3%
Final simplification71.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000185) (not (<= eps 0.00185))) (+ -1.0 (cos eps)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000185) || !(eps <= 0.00185)) {
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.000185d0)) .or. (.not. (eps <= 0.00185d0))) 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.000185) || !(eps <= 0.00185)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000185) or not (eps <= 0.00185): tmp = -1.0 + math.cos(eps) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000185) || !(eps <= 0.00185)) 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.000185) || ~((eps <= 0.00185))) tmp = -1.0 + cos(eps); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000185], N[Not[LessEqual[eps, 0.00185]], $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.000185 \lor \neg \left(\varepsilon \leq 0.00185\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -1.85e-4 or 0.0018500000000000001 < eps Initial program 58.7%
Taylor expanded in x around 0 58.6%
if -1.85e-4 < eps < 0.0018500000000000001Initial program 17.1%
Taylor expanded in eps around 0 82.3%
mul-1-neg82.3%
*-commutative82.3%
distribute-rgt-neg-in82.3%
Simplified82.3%
Final simplification70.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000185) (not (<= eps 0.00013))) (+ -1.0 (cos eps)) (* -0.5 (* eps eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000185) || !(eps <= 0.00013)) {
tmp = -1.0 + cos(eps);
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.000185d0)) .or. (.not. (eps <= 0.00013d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = (-0.5d0) * (eps * eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.000185) || !(eps <= 0.00013)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000185) or not (eps <= 0.00013): tmp = -1.0 + math.cos(eps) else: tmp = -0.5 * (eps * eps) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000185) || !(eps <= 0.00013)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(-0.5 * Float64(eps * eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000185) || ~((eps <= 0.00013))) tmp = -1.0 + cos(eps); else tmp = -0.5 * (eps * eps); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000185], N[Not[LessEqual[eps, 0.00013]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000185 \lor \neg \left(\varepsilon \leq 0.00013\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.85e-4 or 1.29999999999999989e-4 < eps Initial program 58.9%
Taylor expanded in x around 0 58.2%
if -1.85e-4 < eps < 1.29999999999999989e-4Initial program 16.6%
Taylor expanded in x around 0 16.7%
Taylor expanded in eps around 0 32.5%
unpow232.5%
Applied egg-rr32.5%
Final simplification45.8%
(FPCore (x eps) :precision binary64 (* -0.5 (* eps eps)))
double code(double x, double eps) {
return -0.5 * (eps * eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-0.5d0) * (eps * eps)
end function
public static double code(double x, double eps) {
return -0.5 * (eps * eps);
}
def code(x, eps): return -0.5 * (eps * eps)
function code(x, eps) return Float64(-0.5 * Float64(eps * eps)) end
function tmp = code(x, eps) tmp = -0.5 * (eps * eps); end
code[x_, eps_] := N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)
\end{array}
Initial program 38.4%
Taylor expanded in x around 0 38.1%
Taylor expanded in eps around 0 17.5%
unpow217.5%
Applied egg-rr17.5%
Final simplification17.5%
(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 38.4%
add-cube-cbrt37.9%
pow337.9%
Applied egg-rr37.9%
Taylor expanded in eps around 0 9.7%
pow-base-19.7%
*-lft-identity9.7%
+-inverses9.7%
Simplified9.7%
Final simplification9.7%
herbie shell --seed 2023321
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))