
(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 11 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 (* 0.5 eps)))) (* -2.0 (* t_0 (fma (cos x) t_0 (* (sin x) (cos (* 0.5 eps))))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * fma(cos(x), t_0, (sin(x) * cos((0.5 * eps)))));
}
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * fma(cos(x), t_0, Float64(sin(x) * cos(Float64(0.5 * eps)))))) end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(-2.0 * N[(t$95$0 * N[(N[Cos[x], $MachinePrecision] * t$95$0 + N[(N[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
-2 \cdot \left(t_0 \cdot \mathsf{fma}\left(\cos x, t_0, \sin x \cdot \cos \left(0.5 \cdot \varepsilon\right)\right)\right)
\end{array}
\end{array}
Initial program 35.4%
diff-cos46.6%
div-inv46.6%
metadata-eval46.6%
div-inv46.6%
+-commutative46.6%
metadata-eval46.6%
Applied egg-rr46.6%
*-commutative46.6%
+-commutative46.6%
associate--l+79.0%
+-inverses79.0%
distribute-lft-in79.0%
metadata-eval79.0%
*-commutative79.0%
associate-+r+79.0%
+-commutative79.0%
Simplified79.0%
distribute-lft-in79.0%
sin-sum99.5%
Applied egg-rr99.5%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.5%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (+ (* t_0 (cos x)) (* (sin x) (cos (* 0.5 eps))))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * ((t_0 * cos(x)) + (sin(x) * cos((0.5 * eps)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = sin((0.5d0 * eps))
code = (-2.0d0) * (t_0 * ((t_0 * cos(x)) + (sin(x) * cos((0.5d0 * eps)))))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
return -2.0 * (t_0 * ((t_0 * Math.cos(x)) + (Math.sin(x) * Math.cos((0.5 * eps)))));
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) return -2.0 * (t_0 * ((t_0 * math.cos(x)) + (math.sin(x) * math.cos((0.5 * eps)))))
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * Float64(Float64(t_0 * cos(x)) + Float64(sin(x) * cos(Float64(0.5 * eps)))))) end
function tmp = code(x, eps) t_0 = sin((0.5 * eps)); tmp = -2.0 * (t_0 * ((t_0 * cos(x)) + (sin(x) * cos((0.5 * eps))))); end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(-2.0 * N[(t$95$0 * N[(N[(t$95$0 * N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
-2 \cdot \left(t_0 \cdot \left(t_0 \cdot \cos x + \sin x \cdot \cos \left(0.5 \cdot \varepsilon\right)\right)\right)
\end{array}
\end{array}
Initial program 35.4%
diff-cos46.6%
div-inv46.6%
metadata-eval46.6%
div-inv46.6%
+-commutative46.6%
metadata-eval46.6%
Applied egg-rr46.6%
*-commutative46.6%
+-commutative46.6%
associate--l+79.0%
+-inverses79.0%
distribute-lft-in79.0%
metadata-eval79.0%
*-commutative79.0%
associate-+r+79.0%
+-commutative79.0%
Simplified79.0%
distribute-lft-in79.0%
sin-sum99.5%
Applied egg-rr99.5%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00015) (not (<= eps 0.00016)))
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps))))
(+
(* (* eps eps) (* (cos x) -0.5))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00015) || !(eps <= 0.00016)) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
} else {
tmp = ((eps * eps) * (cos(x) * -0.5)) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - 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.00015d0)) .or. (.not. (eps <= 0.00016d0))) then
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)))
else
tmp = ((eps * eps) * (cos(x) * (-0.5d0))) + (sin(x) * ((0.16666666666666666d0 * (eps ** 3.0d0)) - eps))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.00015) || !(eps <= 0.00016)) {
tmp = (Math.cos(x) * Math.cos(eps)) - (Math.cos(x) + (Math.sin(x) * Math.sin(eps)));
} else {
tmp = ((eps * eps) * (Math.cos(x) * -0.5)) + (Math.sin(x) * ((0.16666666666666666 * Math.pow(eps, 3.0)) - eps));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00015) or not (eps <= 0.00016): tmp = (math.cos(x) * math.cos(eps)) - (math.cos(x) + (math.sin(x) * math.sin(eps))) else: tmp = ((eps * eps) * (math.cos(x) * -0.5)) + (math.sin(x) * ((0.16666666666666666 * math.pow(eps, 3.0)) - eps)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00015) || !(eps <= 0.00016)) tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(x) * sin(eps)))); else tmp = Float64(Float64(Float64(eps * eps) * Float64(cos(x) * -0.5)) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00015) || ~((eps <= 0.00016))) tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps))); else tmp = ((eps * eps) * (cos(x) * -0.5)) + (sin(x) * ((0.16666666666666666 * (eps ^ 3.0)) - eps)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00015], N[Not[LessEqual[eps, 0.00016]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(eps * eps), $MachinePrecision] * N[(N[Cos[x], $MachinePrecision] * -0.5), $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.00015 \lor \neg \left(\varepsilon \leq 0.00016\right):\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\cos x \cdot -0.5\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.49999999999999987e-4 or 1.60000000000000013e-4 < eps Initial program 53.0%
cos-sum98.8%
Applied egg-rr98.8%
Taylor expanded in x around inf 98.8%
if -1.49999999999999987e-4 < eps < 1.60000000000000013e-4Initial program 21.1%
Taylor expanded in eps around 0 99.9%
associate-+r+99.8%
+-commutative99.8%
associate-+l+99.8%
*-commutative99.8%
associate-*l*99.8%
unpow299.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.9%
mul-1-neg99.9%
Simplified99.9%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (cos x) (cos eps))) (t_1 (* (sin x) (sin eps))))
(if (<= eps -0.00015)
(- (- t_0 t_1) (cos x))
(if (<= eps 0.00016)
(+
(* (* eps eps) (* (cos x) -0.5))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))
(- t_0 (+ (cos x) t_1))))))
double code(double x, double eps) {
double t_0 = cos(x) * cos(eps);
double t_1 = sin(x) * sin(eps);
double tmp;
if (eps <= -0.00015) {
tmp = (t_0 - t_1) - cos(x);
} else if (eps <= 0.00016) {
tmp = ((eps * eps) * (cos(x) * -0.5)) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - eps));
} else {
tmp = t_0 - (cos(x) + t_1);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos(x) * cos(eps)
t_1 = sin(x) * sin(eps)
if (eps <= (-0.00015d0)) then
tmp = (t_0 - t_1) - cos(x)
else if (eps <= 0.00016d0) then
tmp = ((eps * eps) * (cos(x) * (-0.5d0))) + (sin(x) * ((0.16666666666666666d0 * (eps ** 3.0d0)) - eps))
else
tmp = t_0 - (cos(x) + t_1)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(x) * Math.cos(eps);
double t_1 = Math.sin(x) * Math.sin(eps);
double tmp;
if (eps <= -0.00015) {
tmp = (t_0 - t_1) - Math.cos(x);
} else if (eps <= 0.00016) {
tmp = ((eps * eps) * (Math.cos(x) * -0.5)) + (Math.sin(x) * ((0.16666666666666666 * Math.pow(eps, 3.0)) - eps));
} else {
tmp = t_0 - (Math.cos(x) + t_1);
}
return tmp;
}
def code(x, eps): t_0 = math.cos(x) * math.cos(eps) t_1 = math.sin(x) * math.sin(eps) tmp = 0 if eps <= -0.00015: tmp = (t_0 - t_1) - math.cos(x) elif eps <= 0.00016: tmp = ((eps * eps) * (math.cos(x) * -0.5)) + (math.sin(x) * ((0.16666666666666666 * math.pow(eps, 3.0)) - eps)) else: tmp = t_0 - (math.cos(x) + t_1) return tmp
function code(x, eps) t_0 = Float64(cos(x) * cos(eps)) t_1 = Float64(sin(x) * sin(eps)) tmp = 0.0 if (eps <= -0.00015) tmp = Float64(Float64(t_0 - t_1) - cos(x)); elseif (eps <= 0.00016) tmp = Float64(Float64(Float64(eps * eps) * Float64(cos(x) * -0.5)) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps))); else tmp = Float64(t_0 - Float64(cos(x) + t_1)); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(x) * cos(eps); t_1 = sin(x) * sin(eps); tmp = 0.0; if (eps <= -0.00015) tmp = (t_0 - t_1) - cos(x); elseif (eps <= 0.00016) tmp = ((eps * eps) * (cos(x) * -0.5)) + (sin(x) * ((0.16666666666666666 * (eps ^ 3.0)) - eps)); else tmp = t_0 - (cos(x) + t_1); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00015], N[(N[(t$95$0 - t$95$1), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00016], N[(N[(N[(eps * eps), $MachinePrecision] * N[(N[Cos[x], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - N[(N[Cos[x], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \cos \varepsilon\\
t_1 := \sin x \cdot \sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.00015:\\
\;\;\;\;\left(t_0 - t_1\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 0.00016:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\cos x \cdot -0.5\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 - \left(\cos x + t_1\right)\\
\end{array}
\end{array}
if eps < -1.49999999999999987e-4Initial program 62.7%
cos-sum98.5%
Applied egg-rr98.5%
if -1.49999999999999987e-4 < eps < 1.60000000000000013e-4Initial program 21.1%
Taylor expanded in eps around 0 99.9%
associate-+r+99.8%
+-commutative99.8%
associate-+l+99.8%
*-commutative99.8%
associate-*l*99.8%
unpow299.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.9%
mul-1-neg99.9%
Simplified99.9%
if 1.60000000000000013e-4 < eps Initial program 45.0%
cos-sum99.1%
Applied egg-rr99.1%
Taylor expanded in x around inf 99.1%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -4e-6) (* -2.0 (pow (sin (* 0.5 eps)) 2.0)) (- (* (* eps eps) (* (cos x) -0.5)) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -4e-6) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
} else {
tmp = ((eps * eps) * (cos(x) * -0.5)) - (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 ((cos((eps + x)) - cos(x)) <= (-4d-6)) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
else
tmp = ((eps * eps) * (cos(x) * (-0.5d0))) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -4e-6) {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
} else {
tmp = ((eps * eps) * (Math.cos(x) * -0.5)) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -4e-6: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) else: tmp = ((eps * eps) * (math.cos(x) * -0.5)) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -4e-6) tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); else tmp = Float64(Float64(Float64(eps * eps) * Float64(cos(x) * -0.5)) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -4e-6) tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); else tmp = ((eps * eps) * (cos(x) * -0.5)) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -4e-6], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(eps * eps), $MachinePrecision] * N[(N[Cos[x], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -4 \cdot 10^{-6}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\cos x \cdot -0.5\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -3.99999999999999982e-6Initial program 77.7%
diff-cos78.3%
div-inv78.3%
metadata-eval78.3%
div-inv78.3%
+-commutative78.3%
metadata-eval78.3%
Applied egg-rr78.3%
*-commutative78.3%
+-commutative78.3%
associate--l+78.3%
+-inverses78.3%
distribute-lft-in78.3%
metadata-eval78.3%
*-commutative78.3%
associate-+r+78.3%
+-commutative78.3%
Simplified78.3%
Taylor expanded in x around 0 78.3%
if -3.99999999999999982e-6 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 17.9%
Taylor expanded in eps around 0 78.5%
+-commutative78.5%
mul-1-neg78.5%
unsub-neg78.5%
*-commutative78.5%
associate-*l*78.5%
unpow278.5%
Simplified78.5%
Final simplification78.4%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -4e-6) (* -2.0 (pow (sin (* 0.5 eps)) 2.0)) (* -2.0 (* (* 0.5 eps) (sin (* 0.5 (+ eps (+ x x))))))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -4e-6) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
} else {
tmp = -2.0 * ((0.5 * eps) * sin((0.5 * (eps + (x + x)))));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((cos((eps + x)) - cos(x)) <= (-4d-6)) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
else
tmp = (-2.0d0) * ((0.5d0 * eps) * sin((0.5d0 * (eps + (x + x)))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -4e-6) {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
} else {
tmp = -2.0 * ((0.5 * eps) * Math.sin((0.5 * (eps + (x + x)))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -4e-6: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) else: tmp = -2.0 * ((0.5 * eps) * math.sin((0.5 * (eps + (x + x))))) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -4e-6) tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); else tmp = Float64(-2.0 * Float64(Float64(0.5 * eps) * sin(Float64(0.5 * Float64(eps + Float64(x + x)))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -4e-6) tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); else tmp = -2.0 * ((0.5 * eps) * sin((0.5 * (eps + (x + x))))); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -4e-6], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(0.5 * eps), $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -4 \cdot 10^{-6}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -3.99999999999999982e-6Initial program 77.7%
diff-cos78.3%
div-inv78.3%
metadata-eval78.3%
div-inv78.3%
+-commutative78.3%
metadata-eval78.3%
Applied egg-rr78.3%
*-commutative78.3%
+-commutative78.3%
associate--l+78.3%
+-inverses78.3%
distribute-lft-in78.3%
metadata-eval78.3%
*-commutative78.3%
associate-+r+78.3%
+-commutative78.3%
Simplified78.3%
Taylor expanded in x around 0 78.3%
if -3.99999999999999982e-6 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 17.9%
diff-cos33.4%
div-inv33.4%
metadata-eval33.4%
div-inv33.4%
+-commutative33.4%
metadata-eval33.4%
Applied egg-rr33.4%
*-commutative33.4%
+-commutative33.4%
associate--l+79.2%
+-inverses79.2%
distribute-lft-in79.2%
metadata-eval79.2%
*-commutative79.2%
associate-+r+79.3%
+-commutative79.3%
Simplified79.3%
Taylor expanded in eps around 0 78.2%
Final simplification78.3%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -4e-6) (+ (cos eps) -1.0) (* -2.0 (* (* 0.5 eps) (sin (* 0.5 (+ eps (+ x x))))))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -4e-6) {
tmp = cos(eps) + -1.0;
} else {
tmp = -2.0 * ((0.5 * eps) * sin((0.5 * (eps + (x + x)))));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((cos((eps + x)) - cos(x)) <= (-4d-6)) then
tmp = cos(eps) + (-1.0d0)
else
tmp = (-2.0d0) * ((0.5d0 * eps) * sin((0.5d0 * (eps + (x + x)))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -4e-6) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = -2.0 * ((0.5 * eps) * Math.sin((0.5 * (eps + (x + x)))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -4e-6: tmp = math.cos(eps) + -1.0 else: tmp = -2.0 * ((0.5 * eps) * math.sin((0.5 * (eps + (x + x))))) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -4e-6) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(-2.0 * Float64(Float64(0.5 * eps) * sin(Float64(0.5 * Float64(eps + Float64(x + x)))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -4e-6) tmp = cos(eps) + -1.0; else tmp = -2.0 * ((0.5 * eps) * sin((0.5 * (eps + (x + x))))); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -4e-6], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(-2.0 * N[(N[(0.5 * eps), $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -4 \cdot 10^{-6}:\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -3.99999999999999982e-6Initial program 77.7%
Taylor expanded in x around 0 77.9%
if -3.99999999999999982e-6 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 17.9%
diff-cos33.4%
div-inv33.4%
metadata-eval33.4%
div-inv33.4%
+-commutative33.4%
metadata-eval33.4%
Applied egg-rr33.4%
*-commutative33.4%
+-commutative33.4%
associate--l+79.2%
+-inverses79.2%
distribute-lft-in79.2%
metadata-eval79.2%
*-commutative79.2%
associate-+r+79.3%
+-commutative79.3%
Simplified79.3%
Taylor expanded in eps around 0 78.2%
Final simplification78.1%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 eps)) (sin (* 0.5 (- eps (* -2.0 x)))))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * eps)) * 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((0.5d0 * eps)) * sin((0.5d0 * (eps - ((-2.0d0) * x)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * eps)) * Math.sin((0.5 * (eps - (-2.0 * x)))));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * eps)) * math.sin((0.5 * (eps - (-2.0 * x)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(Float64(0.5 * Float64(eps - Float64(-2.0 * x)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * eps)) * sin((0.5 * (eps - (-2.0 * x))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * eps), $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(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right)\right)
\end{array}
Initial program 35.4%
diff-cos46.6%
div-inv46.6%
metadata-eval46.6%
div-inv46.6%
+-commutative46.6%
metadata-eval46.6%
Applied egg-rr46.6%
*-commutative46.6%
+-commutative46.6%
associate--l+79.0%
+-inverses79.0%
distribute-lft-in79.0%
metadata-eval79.0%
*-commutative79.0%
associate-+r+79.0%
+-commutative79.0%
Simplified79.0%
Taylor expanded in x around -inf 79.0%
Final simplification79.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -2.5e-5) (not (<= eps 9e+28))) (+ (cos eps) -1.0) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -2.5e-5) || !(eps <= 9e+28)) {
tmp = cos(eps) + -1.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) :: tmp
if ((eps <= (-2.5d-5)) .or. (.not. (eps <= 9d+28))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -2.5e-5) || !(eps <= 9e+28)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -2.5e-5) or not (eps <= 9e+28): tmp = math.cos(eps) + -1.0 else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -2.5e-5) || !(eps <= 9e+28)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -2.5e-5) || ~((eps <= 9e+28))) tmp = cos(eps) + -1.0; else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -2.5e-5], N[Not[LessEqual[eps, 9e+28]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.5 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 9 \cdot 10^{+28}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -2.50000000000000012e-5 or 8.9999999999999994e28 < eps Initial program 54.4%
Taylor expanded in x around 0 55.3%
if -2.50000000000000012e-5 < eps < 8.9999999999999994e28Initial program 20.7%
Taylor expanded in eps around 0 77.9%
mul-1-neg77.9%
*-commutative77.9%
distribute-rgt-neg-in77.9%
Simplified77.9%
Final simplification68.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000116) (not (<= eps 1.2e-9))) (+ (cos eps) -1.0) (* (* eps eps) -0.5)))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000116) || !(eps <= 1.2e-9)) {
tmp = cos(eps) + -1.0;
} 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 <= (-0.000116d0)) .or. (.not. (eps <= 1.2d-9))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = (eps * eps) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.000116) || !(eps <= 1.2e-9)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = (eps * eps) * -0.5;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000116) or not (eps <= 1.2e-9): tmp = math.cos(eps) + -1.0 else: tmp = (eps * eps) * -0.5 return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000116) || !(eps <= 1.2e-9)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(Float64(eps * eps) * -0.5); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000116) || ~((eps <= 1.2e-9))) tmp = cos(eps) + -1.0; else tmp = (eps * eps) * -0.5; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000116], N[Not[LessEqual[eps, 1.2e-9]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000116 \lor \neg \left(\varepsilon \leq 1.2 \cdot 10^{-9}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\end{array}
\end{array}
if eps < -1.16e-4 or 1.2e-9 < eps Initial program 52.6%
Taylor expanded in x around 0 53.6%
if -1.16e-4 < eps < 1.2e-9Initial program 21.2%
Taylor expanded in x around 0 21.3%
Taylor expanded in eps around 0 40.6%
*-commutative40.6%
unpow240.6%
Simplified40.6%
Final simplification46.5%
(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(Float64(eps * eps) * -0.5) end
function tmp = code(x, eps) tmp = (eps * eps) * -0.5; end
code[x_, eps_] := N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5
\end{array}
Initial program 35.4%
Taylor expanded in x around 0 35.9%
Taylor expanded in eps around 0 23.8%
*-commutative23.8%
unpow223.8%
Simplified23.8%
Final simplification23.8%
herbie shell --seed 2023278
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))