
(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))))
(if (<= eps -0.0027)
(fma (sin x) t_0 (* (cos x) (+ -1.0 (cos eps))))
(if (<= eps 0.0019)
(fma
0.041666666666666664
(* (cos x) (pow eps 4.0))
(+
(* -0.5 (* eps (* eps (cos x))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps))))
(- (fma (cos x) (cos eps) (* (sin x) t_0)) (cos x))))))
double code(double x, double eps) {
double t_0 = -sin(eps);
double tmp;
if (eps <= -0.0027) {
tmp = fma(sin(x), t_0, (cos(x) * (-1.0 + cos(eps))));
} else if (eps <= 0.0019) {
tmp = fma(0.041666666666666664, (cos(x) * pow(eps, 4.0)), ((-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - eps))));
} else {
tmp = fma(cos(x), cos(eps), (sin(x) * t_0)) - cos(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64(-sin(eps)) tmp = 0.0 if (eps <= -0.0027) tmp = fma(sin(x), t_0, Float64(cos(x) * Float64(-1.0 + cos(eps)))); elseif (eps <= 0.0019) tmp = fma(0.041666666666666664, Float64(cos(x) * (eps ^ 4.0)), Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps)))); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(x) * t_0)) - cos(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = (-N[Sin[eps], $MachinePrecision])}, If[LessEqual[eps, -0.0027], N[(N[Sin[x], $MachinePrecision] * t$95$0 + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.0019], N[(0.041666666666666664 * N[(N[Cos[x], $MachinePrecision] * N[Power[eps, 4.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.0027:\\
\;\;\;\;\mathsf{fma}\left(\sin x, t_0, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.0019:\\
\;\;\;\;\mathsf{fma}\left(0.041666666666666664, \cos x \cdot {\varepsilon}^{4}, -0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin x \cdot t_0\right) - \cos x\\
\end{array}
\end{array}
if eps < -0.0027000000000000001Initial program 56.5%
cos-sum99.1%
cancel-sign-sub-inv99.1%
fma-def99.1%
Applied egg-rr99.1%
Taylor expanded in x around inf 99.1%
neg-mul-199.1%
distribute-lft-neg-in99.1%
associate--l+99.1%
*-commutative99.1%
distribute-lft-neg-in99.1%
distribute-rgt-neg-in99.1%
fma-def99.1%
*-rgt-identity99.1%
distribute-lft-out--99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
if -0.0027000000000000001 < eps < 0.0019Initial program 20.1%
Taylor expanded in eps around 0 99.8%
fma-def99.8%
*-commutative99.8%
+-commutative99.8%
associate-+l+99.8%
unpow299.8%
associate-*l*99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
mul-1-neg99.8%
Simplified99.8%
if 0.0019 < eps Initial program 46.8%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def99.0%
Applied egg-rr99.0%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (sin eps))))
(if (<= eps -0.000165)
(fma (sin x) t_0 (* (cos x) (+ -1.0 (cos eps))))
(if (<= eps 0.00016)
(+
(* -0.5 (* eps (* eps (cos x))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))
(- (fma (cos x) (cos eps) (* (sin x) t_0)) (cos x))))))
double code(double x, double eps) {
double t_0 = -sin(eps);
double tmp;
if (eps <= -0.000165) {
tmp = fma(sin(x), t_0, (cos(x) * (-1.0 + cos(eps))));
} else if (eps <= 0.00016) {
tmp = (-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - eps));
} else {
tmp = fma(cos(x), cos(eps), (sin(x) * t_0)) - cos(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64(-sin(eps)) tmp = 0.0 if (eps <= -0.000165) tmp = fma(sin(x), t_0, Float64(cos(x) * Float64(-1.0 + cos(eps)))); elseif (eps <= 0.00016) tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps))); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(x) * t_0)) - cos(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = (-N[Sin[eps], $MachinePrecision])}, If[LessEqual[eps, -0.000165], N[(N[Sin[x], $MachinePrecision] * t$95$0 + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00016], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.000165:\\
\;\;\;\;\mathsf{fma}\left(\sin x, t_0, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00016:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin x \cdot t_0\right) - \cos x\\
\end{array}
\end{array}
if eps < -1.65e-4Initial program 56.6%
cos-sum98.5%
cancel-sign-sub-inv98.5%
fma-def98.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 98.5%
neg-mul-198.5%
distribute-lft-neg-in98.5%
associate--l+98.5%
*-commutative98.5%
distribute-lft-neg-in98.5%
distribute-rgt-neg-in98.5%
fma-def98.5%
*-rgt-identity98.5%
distribute-lft-out--98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
Simplified98.5%
if -1.65e-4 < eps < 1.60000000000000013e-4Initial program 19.7%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
associate-+l+99.7%
unpow299.7%
associate-*l*99.7%
associate-*r*99.7%
associate-*r*99.7%
distribute-rgt-out99.7%
mul-1-neg99.7%
Simplified99.7%
if 1.60000000000000013e-4 < eps Initial program 46.8%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def99.0%
Applied egg-rr99.0%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.000165)
(fma (sin x) (- (sin eps)) (* (cos x) (+ -1.0 (cos eps))))
(if (<= eps 0.000145)
(+
(* -0.5 (* eps (* eps (cos x))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps)))))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.000165) {
tmp = fma(sin(x), -sin(eps), (cos(x) * (-1.0 + cos(eps))));
} else if (eps <= 0.000145) {
tmp = (-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - eps));
} else {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.000165) tmp = fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(-1.0 + cos(eps)))); elseif (eps <= 0.000145) tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps))); else tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(x) * sin(eps)))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.000165], N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.000145], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000165:\\
\;\;\;\;\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.000145:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.65e-4Initial program 56.6%
cos-sum98.5%
cancel-sign-sub-inv98.5%
fma-def98.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 98.5%
neg-mul-198.5%
distribute-lft-neg-in98.5%
associate--l+98.5%
*-commutative98.5%
distribute-lft-neg-in98.5%
distribute-rgt-neg-in98.5%
fma-def98.5%
*-rgt-identity98.5%
distribute-lft-out--98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
Simplified98.5%
if -1.65e-4 < eps < 1.45e-4Initial program 19.7%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
associate-+l+99.7%
unpow299.7%
associate-*l*99.7%
associate-*r*99.7%
associate-*r*99.7%
distribute-rgt-out99.7%
mul-1-neg99.7%
Simplified99.7%
if 1.45e-4 < eps Initial program 46.8%
sub-neg46.8%
cos-sum98.9%
associate-+l-98.9%
fma-neg98.9%
Applied egg-rr98.9%
Taylor expanded in x around -inf 98.9%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.000165) (not (<= eps 0.00013)))
(fma (sin x) (- (sin eps)) (* (cos x) (+ -1.0 (cos eps))))
(+
(* -0.5 (* eps (* eps (cos x))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000165) || !(eps <= 0.00013)) {
tmp = fma(sin(x), -sin(eps), (cos(x) * (-1.0 + cos(eps))));
} else {
tmp = (-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - eps));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -0.000165) || !(eps <= 0.00013)) tmp = fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(-1.0 + cos(eps)))); else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000165], N[Not[LessEqual[eps, 0.00013]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000165 \lor \neg \left(\varepsilon \leq 0.00013\right):\\
\;\;\;\;\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.65e-4 or 1.29999999999999989e-4 < eps Initial program 51.5%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.8%
Applied egg-rr98.8%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
distribute-lft-neg-in98.7%
associate--l+98.7%
*-commutative98.7%
distribute-lft-neg-in98.7%
distribute-rgt-neg-in98.7%
fma-def98.7%
*-rgt-identity98.7%
distribute-lft-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
Simplified98.7%
if -1.65e-4 < eps < 1.29999999999999989e-4Initial program 19.7%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
associate-+l+99.7%
unpow299.7%
associate-*l*99.7%
associate-*r*99.7%
associate-*r*99.7%
distribute-rgt-out99.7%
mul-1-neg99.7%
Simplified99.7%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- (cos (+ eps x)) (cos x)))) (if (<= t_0 -2e-8) t_0 (* eps (- (sin x))))))
double code(double x, double eps) {
double t_0 = cos((eps + x)) - cos(x);
double tmp;
if (t_0 <= -2e-8) {
tmp = t_0;
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = cos((eps + x)) - cos(x)
if (t_0 <= (-2d-8)) then
tmp = t_0
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos((eps + x)) - Math.cos(x);
double tmp;
if (t_0 <= -2e-8) {
tmp = t_0;
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): t_0 = math.cos((eps + x)) - math.cos(x) tmp = 0 if t_0 <= -2e-8: tmp = t_0 else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) t_0 = Float64(cos(Float64(eps + x)) - cos(x)) tmp = 0.0 if (t_0 <= -2e-8) tmp = t_0; else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos((eps + x)) - cos(x); tmp = 0.0; if (t_0 <= -2e-8) tmp = t_0; else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-8], t$95$0, N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\varepsilon + x\right) - \cos x\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{-8}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -2e-8Initial program 80.4%
if -2e-8 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 15.9%
Taylor expanded in eps around 0 57.6%
associate-*r*57.6%
mul-1-neg57.6%
Simplified57.6%
Final simplification64.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.02) (not (<= eps 0.66))) (- (cos eps) (cos x)) (- (* -0.5 (* eps (* eps (cos x)))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.02) || !(eps <= 0.66)) {
tmp = cos(eps) - cos(x);
} else {
tmp = (-0.5 * (eps * (eps * cos(x)))) - (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.02d0)) .or. (.not. (eps <= 0.66d0))) then
tmp = cos(eps) - cos(x)
else
tmp = ((-0.5d0) * (eps * (eps * cos(x)))) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.02) || !(eps <= 0.66)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.02) or not (eps <= 0.66): tmp = math.cos(eps) - math.cos(x) else: tmp = (-0.5 * (eps * (eps * math.cos(x)))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.02) || !(eps <= 0.66)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.02) || ~((eps <= 0.66))) tmp = cos(eps) - cos(x); else tmp = (-0.5 * (eps * (eps * cos(x)))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.02], N[Not[LessEqual[eps, 0.66]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.02 \lor \neg \left(\varepsilon \leq 0.66\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -0.0200000000000000004 or 0.660000000000000031 < eps Initial program 52.1%
Taylor expanded in x around 0 54.1%
if -0.0200000000000000004 < eps < 0.660000000000000031Initial program 19.8%
Taylor expanded in eps around 0 98.2%
mul-1-neg98.2%
unsub-neg98.2%
unpow298.2%
associate-*l*98.2%
Simplified98.2%
Final simplification76.0%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* eps 0.5)) (sin (* 0.5 (+ x (+ eps x)))))))
double code(double x, double eps) {
return -2.0 * (sin((eps * 0.5)) * sin((0.5 * (x + (eps + 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 * (x + (eps + x)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((eps * 0.5)) * Math.sin((0.5 * (x + (eps + x)))));
}
def code(x, eps): return -2.0 * (math.sin((eps * 0.5)) * math.sin((0.5 * (x + (eps + x)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(eps * 0.5)) * sin(Float64(0.5 * Float64(x + Float64(eps + x)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((eps * 0.5)) * sin((0.5 * (x + (eps + x))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(x + N[(eps + 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(x + \left(\varepsilon + x\right)\right)\right)\right)
\end{array}
Initial program 36.1%
diff-cos44.9%
div-inv44.9%
metadata-eval44.9%
div-inv44.9%
+-commutative44.9%
metadata-eval44.9%
Applied egg-rr44.9%
*-commutative44.9%
+-commutative44.9%
associate--l+75.0%
+-inverses75.0%
distribute-lft-in75.0%
metadata-eval75.0%
*-commutative75.0%
+-commutative75.0%
Simplified75.0%
log1p-expm1-u75.0%
*-commutative75.0%
+-commutative75.0%
+-rgt-identity75.0%
Applied egg-rr75.0%
log1p-expm1-u75.0%
+-commutative75.0%
Applied egg-rr75.0%
Final simplification75.0%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 (- eps (* x -2.0)))) (sin (* eps 0.5)))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * (eps - (x * -2.0)))) * sin((eps * 0.5)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((0.5d0 * (eps - (x * (-2.0d0))))) * sin((eps * 0.5d0)))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * (eps - (x * -2.0)))) * Math.sin((eps * 0.5)));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * (eps - (x * -2.0)))) * math.sin((eps * 0.5)))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))) * sin(Float64(eps * 0.5)))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * (eps - (x * -2.0)))) * sin((eps * 0.5))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * N[(eps - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 36.1%
diff-cos44.9%
div-inv44.9%
metadata-eval44.9%
div-inv44.9%
+-commutative44.9%
metadata-eval44.9%
Applied egg-rr44.9%
*-commutative44.9%
+-commutative44.9%
associate--l+75.0%
+-inverses75.0%
distribute-lft-in75.0%
metadata-eval75.0%
*-commutative75.0%
+-commutative75.0%
Simplified75.0%
Taylor expanded in x around -inf 75.0%
Final simplification75.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (cos eps) (cos x))) (t_1 (* eps (- (sin x)))))
(if (<= eps -2.4e-5)
t_0
(if (<= eps 2.6e-55)
t_1
(if (<= eps 7e-13) (* eps (* eps -0.5)) (if (<= eps 0.66) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = cos(eps) - cos(x);
double t_1 = eps * -sin(x);
double tmp;
if (eps <= -2.4e-5) {
tmp = t_0;
} else if (eps <= 2.6e-55) {
tmp = t_1;
} else if (eps <= 7e-13) {
tmp = eps * (eps * -0.5);
} else if (eps <= 0.66) {
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 = cos(eps) - cos(x)
t_1 = eps * -sin(x)
if (eps <= (-2.4d-5)) then
tmp = t_0
else if (eps <= 2.6d-55) then
tmp = t_1
else if (eps <= 7d-13) then
tmp = eps * (eps * (-0.5d0))
else if (eps <= 0.66d0) 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 = Math.cos(eps) - Math.cos(x);
double t_1 = eps * -Math.sin(x);
double tmp;
if (eps <= -2.4e-5) {
tmp = t_0;
} else if (eps <= 2.6e-55) {
tmp = t_1;
} else if (eps <= 7e-13) {
tmp = eps * (eps * -0.5);
} else if (eps <= 0.66) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) - math.cos(x) t_1 = eps * -math.sin(x) tmp = 0 if eps <= -2.4e-5: tmp = t_0 elif eps <= 2.6e-55: tmp = t_1 elif eps <= 7e-13: tmp = eps * (eps * -0.5) elif eps <= 0.66: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) - cos(x)) t_1 = Float64(eps * Float64(-sin(x))) tmp = 0.0 if (eps <= -2.4e-5) tmp = t_0; elseif (eps <= 2.6e-55) tmp = t_1; elseif (eps <= 7e-13) tmp = Float64(eps * Float64(eps * -0.5)); elseif (eps <= 0.66) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) - cos(x); t_1 = eps * -sin(x); tmp = 0.0; if (eps <= -2.4e-5) tmp = t_0; elseif (eps <= 2.6e-55) tmp = t_1; elseif (eps <= 7e-13) tmp = eps * (eps * -0.5); elseif (eps <= 0.66) tmp = t_1; 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]}, Block[{t$95$1 = N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[eps, -2.4e-5], t$95$0, If[LessEqual[eps, 2.6e-55], t$95$1, If[LessEqual[eps, 7e-13], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.66], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon - \cos x\\
t_1 := \varepsilon \cdot \left(-\sin x\right)\\
\mathbf{if}\;\varepsilon \leq -2.4 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 2.6 \cdot 10^{-55}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 7 \cdot 10^{-13}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\mathbf{elif}\;\varepsilon \leq 0.66:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -2.4000000000000001e-5 or 0.660000000000000031 < eps Initial program 51.8%
Taylor expanded in x around 0 53.8%
if -2.4000000000000001e-5 < eps < 2.5999999999999999e-55 or 7.0000000000000005e-13 < eps < 0.660000000000000031Initial program 20.7%
Taylor expanded in eps around 0 84.0%
associate-*r*84.0%
mul-1-neg84.0%
Simplified84.0%
if 2.5999999999999999e-55 < eps < 7.0000000000000005e-13Initial program 3.7%
Taylor expanded in x around 0 3.7%
Taylor expanded in eps around 0 87.7%
*-commutative87.7%
unpow287.7%
associate-*l*87.7%
Simplified87.7%
Final simplification68.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -2.95e-18) (not (<= x 1.5e-27)))
(* -2.0 (* (sin x) 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 <= -2.95e-18) || !(x <= 1.5e-27)) {
tmp = -2.0 * (sin(x) * 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 <= (-2.95d-18)) .or. (.not. (x <= 1.5d-27))) then
tmp = (-2.0d0) * (sin(x) * 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 <= -2.95e-18) || !(x <= 1.5e-27)) {
tmp = -2.0 * (Math.sin(x) * 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 <= -2.95e-18) or not (x <= 1.5e-27): tmp = -2.0 * (math.sin(x) * 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 <= -2.95e-18) || !(x <= 1.5e-27)) tmp = Float64(-2.0 * Float64(sin(x) * 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 <= -2.95e-18) || ~((x <= 1.5e-27))) tmp = -2.0 * (sin(x) * 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, -2.95e-18], N[Not[LessEqual[x, 1.5e-27]], $MachinePrecision]], N[(-2.0 * N[(N[Sin[x], $MachinePrecision] * 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 -2.95 \cdot 10^{-18} \lor \neg \left(x \leq 1.5 \cdot 10^{-27}\right):\\
\;\;\;\;-2 \cdot \left(\sin x \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -2.9500000000000001e-18 or 1.5000000000000001e-27 < x Initial program 10.2%
diff-cos9.3%
div-inv9.3%
metadata-eval9.3%
div-inv9.3%
+-commutative9.3%
metadata-eval9.3%
Applied egg-rr9.3%
*-commutative9.3%
+-commutative9.3%
associate--l+56.4%
+-inverses56.4%
distribute-lft-in56.4%
metadata-eval56.4%
*-commutative56.4%
+-commutative56.4%
Simplified56.4%
Taylor expanded in x around -inf 56.4%
Taylor expanded in eps around 0 52.9%
if -2.9500000000000001e-18 < x < 1.5000000000000001e-27Initial program 70.5%
diff-cos92.2%
div-inv92.2%
metadata-eval92.2%
div-inv92.2%
+-commutative92.2%
metadata-eval92.2%
Applied egg-rr92.2%
*-commutative92.2%
+-commutative92.2%
associate--l+99.7%
+-inverses99.7%
distribute-lft-in99.7%
metadata-eval99.7%
*-commutative99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in x around 0 91.2%
Final simplification69.3%
(FPCore (x eps) :precision binary64 (if (or (<= x -4.7e-18) (not (<= x 2.15e-26))) (* eps (- (sin x))) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -4.7e-18) || !(x <= 2.15e-26)) {
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 <= (-4.7d-18)) .or. (.not. (x <= 2.15d-26))) 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 <= -4.7e-18) || !(x <= 2.15e-26)) {
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 <= -4.7e-18) or not (x <= 2.15e-26): 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 <= -4.7e-18) || !(x <= 2.15e-26)) 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 <= -4.7e-18) || ~((x <= 2.15e-26))) 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, -4.7e-18], N[Not[LessEqual[x, 2.15e-26]], $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 -4.7 \cdot 10^{-18} \lor \neg \left(x \leq 2.15 \cdot 10^{-26}\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 < -4.6999999999999996e-18 or 2.14999999999999994e-26 < x Initial program 10.2%
Taylor expanded in eps around 0 50.0%
associate-*r*50.0%
mul-1-neg50.0%
Simplified50.0%
if -4.6999999999999996e-18 < x < 2.14999999999999994e-26Initial program 70.5%
diff-cos92.2%
div-inv92.2%
metadata-eval92.2%
div-inv92.2%
+-commutative92.2%
metadata-eval92.2%
Applied egg-rr92.2%
*-commutative92.2%
+-commutative92.2%
associate--l+99.7%
+-inverses99.7%
distribute-lft-in99.7%
metadata-eval99.7%
*-commutative99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in x around 0 91.2%
Final simplification67.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (* eps (- (sin x)))))
(if (<= eps -8.5e-5)
t_0
(if (<= eps 3.6e-53)
t_1
(if (<= eps 8.2e-13)
(* eps (* eps -0.5))
(if (<= eps 0.66) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = eps * -sin(x);
double tmp;
if (eps <= -8.5e-5) {
tmp = t_0;
} else if (eps <= 3.6e-53) {
tmp = t_1;
} else if (eps <= 8.2e-13) {
tmp = eps * (eps * -0.5);
} else if (eps <= 0.66) {
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 = eps * -sin(x)
if (eps <= (-8.5d-5)) then
tmp = t_0
else if (eps <= 3.6d-53) then
tmp = t_1
else if (eps <= 8.2d-13) then
tmp = eps * (eps * (-0.5d0))
else if (eps <= 0.66d0) 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 = eps * -Math.sin(x);
double tmp;
if (eps <= -8.5e-5) {
tmp = t_0;
} else if (eps <= 3.6e-53) {
tmp = t_1;
} else if (eps <= 8.2e-13) {
tmp = eps * (eps * -0.5);
} else if (eps <= 0.66) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) t_1 = eps * -math.sin(x) tmp = 0 if eps <= -8.5e-5: tmp = t_0 elif eps <= 3.6e-53: tmp = t_1 elif eps <= 8.2e-13: tmp = eps * (eps * -0.5) elif eps <= 0.66: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(eps * Float64(-sin(x))) tmp = 0.0 if (eps <= -8.5e-5) tmp = t_0; elseif (eps <= 3.6e-53) tmp = t_1; elseif (eps <= 8.2e-13) tmp = Float64(eps * Float64(eps * -0.5)); elseif (eps <= 0.66) 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 = eps * -sin(x); tmp = 0.0; if (eps <= -8.5e-5) tmp = t_0; elseif (eps <= 3.6e-53) tmp = t_1; elseif (eps <= 8.2e-13) tmp = eps * (eps * -0.5); elseif (eps <= 0.66) 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[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[eps, -8.5e-5], t$95$0, If[LessEqual[eps, 3.6e-53], t$95$1, If[LessEqual[eps, 8.2e-13], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.66], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := \varepsilon \cdot \left(-\sin x\right)\\
\mathbf{if}\;\varepsilon \leq -8.5 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 3.6 \cdot 10^{-53}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 8.2 \cdot 10^{-13}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\mathbf{elif}\;\varepsilon \leq 0.66:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -8.500000000000001e-5 or 0.660000000000000031 < eps Initial program 51.8%
Taylor expanded in x around 0 50.8%
if -8.500000000000001e-5 < eps < 3.5999999999999999e-53 or 8.2000000000000004e-13 < eps < 0.660000000000000031Initial program 20.7%
Taylor expanded in eps around 0 84.0%
associate-*r*84.0%
mul-1-neg84.0%
Simplified84.0%
if 3.5999999999999999e-53 < eps < 8.2000000000000004e-13Initial program 3.7%
Taylor expanded in x around 0 3.7%
Taylor expanded in eps around 0 87.7%
*-commutative87.7%
unpow287.7%
associate-*l*87.7%
Simplified87.7%
Final simplification67.1%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.76e-6) (not (<= eps 0.00013))) (+ -1.0 (cos eps)) (* eps (* eps -0.5))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.76e-6) || !(eps <= 0.00013)) {
tmp = -1.0 + cos(eps);
} else {
tmp = eps * (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 <= (-1.76d-6)) .or. (.not. (eps <= 0.00013d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = eps * (eps * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.76e-6) || !(eps <= 0.00013)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * (eps * -0.5);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.76e-6) or not (eps <= 0.00013): tmp = -1.0 + math.cos(eps) else: tmp = eps * (eps * -0.5) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.76e-6) || !(eps <= 0.00013)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(eps * Float64(eps * -0.5)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.76e-6) || ~((eps <= 0.00013))) tmp = -1.0 + cos(eps); else tmp = eps * (eps * -0.5); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.76e-6], N[Not[LessEqual[eps, 0.00013]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.76 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 0.00013\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\end{array}
\end{array}
if eps < -1.7600000000000001e-6 or 1.29999999999999989e-4 < eps Initial program 51.1%
Taylor expanded in x around 0 50.1%
if -1.7600000000000001e-6 < eps < 1.29999999999999989e-4Initial program 19.9%
Taylor expanded in x around 0 19.7%
Taylor expanded in eps around 0 38.1%
*-commutative38.1%
unpow238.1%
associate-*l*38.1%
Simplified38.1%
Final simplification44.4%
(FPCore (x eps) :precision binary64 (if (<= eps 6.2e+31) (* eps (* eps -0.5)) (- 1.0 (cos x))))
double code(double x, double eps) {
double tmp;
if (eps <= 6.2e+31) {
tmp = eps * (eps * -0.5);
} else {
tmp = 1.0 - 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 <= 6.2d+31) then
tmp = eps * (eps * (-0.5d0))
else
tmp = 1.0d0 - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= 6.2e+31) {
tmp = eps * (eps * -0.5);
} else {
tmp = 1.0 - Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= 6.2e+31: tmp = eps * (eps * -0.5) else: tmp = 1.0 - math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= 6.2e+31) tmp = Float64(eps * Float64(eps * -0.5)); else tmp = Float64(1.0 - cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= 6.2e+31) tmp = eps * (eps * -0.5); else tmp = 1.0 - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, 6.2e+31], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 6.2 \cdot 10^{+31}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \cos x\\
\end{array}
\end{array}
if eps < 6.2000000000000004e31Initial program 32.7%
Taylor expanded in x around 0 32.6%
Taylor expanded in eps around 0 25.9%
*-commutative25.9%
unpow225.9%
associate-*l*25.9%
Simplified25.9%
if 6.2000000000000004e31 < eps Initial program 46.7%
Taylor expanded in x around 0 42.2%
mul-1-neg42.2%
unsub-neg42.2%
Simplified42.2%
Taylor expanded in eps around 0 9.8%
Final simplification22.0%
(FPCore (x eps) :precision binary64 (* 0.5 (* x x)))
double code(double x, double eps) {
return 0.5 * (x * x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.5d0 * (x * x)
end function
public static double code(double x, double eps) {
return 0.5 * (x * x);
}
def code(x, eps): return 0.5 * (x * x)
function code(x, eps) return Float64(0.5 * Float64(x * x)) end
function tmp = code(x, eps) tmp = 0.5 * (x * x); end
code[x_, eps_] := N[(0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot x\right)
\end{array}
Initial program 36.1%
Taylor expanded in x around 0 33.5%
mul-1-neg33.5%
unsub-neg33.5%
Simplified33.5%
Taylor expanded in eps around 0 13.0%
Taylor expanded in x around 0 8.0%
unpow28.0%
Simplified8.0%
Final simplification8.0%
(FPCore (x eps) :precision binary64 (* eps (* eps -0.5)))
double code(double x, double eps) {
return eps * (eps * -0.5);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * (eps * (-0.5d0))
end function
public static double code(double x, double eps) {
return eps * (eps * -0.5);
}
def code(x, eps): return eps * (eps * -0.5)
function code(x, eps) return Float64(eps * Float64(eps * -0.5)) end
function tmp = code(x, eps) tmp = eps * (eps * -0.5); end
code[x_, eps_] := N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)
\end{array}
Initial program 36.1%
Taylor expanded in x around 0 35.5%
Taylor expanded in eps around 0 20.3%
*-commutative20.3%
unpow220.3%
associate-*l*20.3%
Simplified20.3%
Final simplification20.3%
herbie shell --seed 2023274
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))