
(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 13 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)))) (* (* t_0 (fma (cos x) t_0 (* (sin x) (cos (* 0.5 eps))))) -2.0)))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return (t_0 * fma(cos(x), t_0, (sin(x) * cos((0.5 * eps))))) * -2.0;
}
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(Float64(t_0 * fma(cos(x), t_0, Float64(sin(x) * cos(Float64(0.5 * eps))))) * -2.0) end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(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] * -2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
\left(t_0 \cdot \mathsf{fma}\left(\cos x, t_0, \sin x \cdot \cos \left(0.5 \cdot \varepsilon\right)\right)\right) \cdot -2
\end{array}
\end{array}
Initial program 43.9%
diff-cos52.9%
div-inv52.9%
metadata-eval52.9%
div-inv52.9%
+-commutative52.9%
metadata-eval52.9%
Applied egg-rr52.9%
*-commutative52.9%
+-commutative52.9%
associate--l+78.1%
+-inverses78.1%
distribute-lft-in78.1%
metadata-eval78.1%
*-commutative78.1%
associate-+r+78.1%
+-commutative78.1%
Simplified78.1%
distribute-lft-in78.1%
sin-sum99.4%
Applied egg-rr99.4%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.4%
*-commutative99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
distribute-lft-neg-in99.4%
metadata-eval99.4%
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 43.9%
diff-cos52.9%
div-inv52.9%
metadata-eval52.9%
div-inv52.9%
+-commutative52.9%
metadata-eval52.9%
Applied egg-rr52.9%
*-commutative52.9%
+-commutative52.9%
associate--l+78.1%
+-inverses78.1%
distribute-lft-in78.1%
metadata-eval78.1%
*-commutative78.1%
associate-+r+78.1%
+-commutative78.1%
Simplified78.1%
distribute-lft-in78.1%
sin-sum99.4%
Applied egg-rr99.4%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.4%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00155) (not (<= eps 0.00325)))
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps))))
(+
(* (cos x) (+ (* 0.041666666666666664 (pow eps 4.0)) (* -0.5 (* eps eps))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00155) || !(eps <= 0.00325)) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
} else {
tmp = (cos(x) * ((0.041666666666666664 * pow(eps, 4.0)) + (-0.5 * (eps * eps)))) + (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.00155d0)) .or. (.not. (eps <= 0.00325d0))) then
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)))
else
tmp = (cos(x) * ((0.041666666666666664d0 * (eps ** 4.0d0)) + ((-0.5d0) * (eps * eps)))) + (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.00155) || !(eps <= 0.00325)) {
tmp = (Math.cos(x) * Math.cos(eps)) - (Math.cos(x) + (Math.sin(x) * Math.sin(eps)));
} else {
tmp = (Math.cos(x) * ((0.041666666666666664 * Math.pow(eps, 4.0)) + (-0.5 * (eps * eps)))) + (Math.sin(x) * ((0.16666666666666666 * Math.pow(eps, 3.0)) - eps));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00155) or not (eps <= 0.00325): tmp = (math.cos(x) * math.cos(eps)) - (math.cos(x) + (math.sin(x) * math.sin(eps))) else: tmp = (math.cos(x) * ((0.041666666666666664 * math.pow(eps, 4.0)) + (-0.5 * (eps * eps)))) + (math.sin(x) * ((0.16666666666666666 * math.pow(eps, 3.0)) - eps)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00155) || !(eps <= 0.00325)) tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(x) * sin(eps)))); else tmp = Float64(Float64(cos(x) * Float64(Float64(0.041666666666666664 * (eps ^ 4.0)) + Float64(-0.5 * Float64(eps * eps)))) + 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.00155) || ~((eps <= 0.00325))) tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps))); else tmp = (cos(x) * ((0.041666666666666664 * (eps ^ 4.0)) + (-0.5 * (eps * eps)))) + (sin(x) * ((0.16666666666666666 * (eps ^ 3.0)) - eps)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00155], N[Not[LessEqual[eps, 0.00325]], $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[Cos[x], $MachinePrecision] * N[(N[(0.041666666666666664 * N[Power[eps, 4.0], $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(eps * eps), $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.00155 \lor \neg \left(\varepsilon \leq 0.00325\right):\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(0.041666666666666664 \cdot {\varepsilon}^{4} + -0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\end{array}
\end{array}
if eps < -0.00154999999999999995 or 0.00324999999999999985 < eps Initial program 57.5%
sub-neg57.5%
cos-sum98.6%
associate-+l-98.5%
fma-neg98.5%
Applied egg-rr98.5%
fma-neg98.5%
*-commutative98.5%
*-commutative98.5%
fma-neg98.5%
remove-double-neg98.5%
Simplified98.5%
fma-udef98.5%
Applied egg-rr98.5%
if -0.00154999999999999995 < eps < 0.00324999999999999985Initial program 28.8%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
associate-+r+99.8%
associate-+l+99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
unpow299.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
Simplified99.8%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00155) (not (<= eps 0.003)))
(- (- (* (cos x) (cos eps)) (* (sin x) (sin eps))) (cos x))
(+
(* (cos x) (+ (* 0.041666666666666664 (pow eps 4.0)) (* -0.5 (* eps eps))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00155) || !(eps <= 0.003)) {
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x);
} else {
tmp = (cos(x) * ((0.041666666666666664 * pow(eps, 4.0)) + (-0.5 * (eps * eps)))) + (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.00155d0)) .or. (.not. (eps <= 0.003d0))) then
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x)
else
tmp = (cos(x) * ((0.041666666666666664d0 * (eps ** 4.0d0)) + ((-0.5d0) * (eps * eps)))) + (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.00155) || !(eps <= 0.003)) {
tmp = ((Math.cos(x) * Math.cos(eps)) - (Math.sin(x) * Math.sin(eps))) - Math.cos(x);
} else {
tmp = (Math.cos(x) * ((0.041666666666666664 * Math.pow(eps, 4.0)) + (-0.5 * (eps * eps)))) + (Math.sin(x) * ((0.16666666666666666 * Math.pow(eps, 3.0)) - eps));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00155) or not (eps <= 0.003): tmp = ((math.cos(x) * math.cos(eps)) - (math.sin(x) * math.sin(eps))) - math.cos(x) else: tmp = (math.cos(x) * ((0.041666666666666664 * math.pow(eps, 4.0)) + (-0.5 * (eps * eps)))) + (math.sin(x) * ((0.16666666666666666 * math.pow(eps, 3.0)) - eps)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00155) || !(eps <= 0.003)) tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - Float64(sin(x) * sin(eps))) - cos(x)); else tmp = Float64(Float64(cos(x) * Float64(Float64(0.041666666666666664 * (eps ^ 4.0)) + Float64(-0.5 * Float64(eps * eps)))) + 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.00155) || ~((eps <= 0.003))) tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x); else tmp = (cos(x) * ((0.041666666666666664 * (eps ^ 4.0)) + (-0.5 * (eps * eps)))) + (sin(x) * ((0.16666666666666666 * (eps ^ 3.0)) - eps)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00155], N[Not[LessEqual[eps, 0.003]], $MachinePrecision]], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[(N[(0.041666666666666664 * N[Power[eps, 4.0], $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(eps * eps), $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.00155 \lor \neg \left(\varepsilon \leq 0.003\right):\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \sin x \cdot \sin \varepsilon\right) - \cos x\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(0.041666666666666664 \cdot {\varepsilon}^{4} + -0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\end{array}
\end{array}
if eps < -0.00154999999999999995 or 0.0030000000000000001 < eps Initial program 57.5%
cos-sum98.6%
Applied egg-rr98.6%
if -0.00154999999999999995 < eps < 0.0030000000000000001Initial program 28.8%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
associate-+r+99.8%
associate-+l+99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
unpow299.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
Simplified99.8%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.0102)
(* (cos x) (+ (cos eps) -1.0))
(if (<= eps 0.0029)
(- (* (* eps eps) (* (cos x) -0.5)) (* eps (sin x)))
(- (cos eps) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0102) {
tmp = cos(x) * (cos(eps) + -1.0);
} else if (eps <= 0.0029) {
tmp = ((eps * eps) * (cos(x) * -0.5)) - (eps * sin(x));
} else {
tmp = cos(eps) - cos(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-0.0102d0)) then
tmp = cos(x) * (cos(eps) + (-1.0d0))
else if (eps <= 0.0029d0) then
tmp = ((eps * eps) * (cos(x) * (-0.5d0))) - (eps * sin(x))
else
tmp = cos(eps) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -0.0102) {
tmp = Math.cos(x) * (Math.cos(eps) + -1.0);
} else if (eps <= 0.0029) {
tmp = ((eps * eps) * (Math.cos(x) * -0.5)) - (eps * Math.sin(x));
} else {
tmp = Math.cos(eps) - Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.0102: tmp = math.cos(x) * (math.cos(eps) + -1.0) elif eps <= 0.0029: tmp = ((eps * eps) * (math.cos(x) * -0.5)) - (eps * math.sin(x)) else: tmp = math.cos(eps) - math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.0102) tmp = Float64(cos(x) * Float64(cos(eps) + -1.0)); elseif (eps <= 0.0029) tmp = Float64(Float64(Float64(eps * eps) * Float64(cos(x) * -0.5)) - Float64(eps * sin(x))); else tmp = Float64(cos(eps) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -0.0102) tmp = cos(x) * (cos(eps) + -1.0); elseif (eps <= 0.0029) tmp = ((eps * eps) * (cos(x) * -0.5)) - (eps * sin(x)); else tmp = cos(eps) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.0102], N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.0029], N[(N[(N[(eps * eps), $MachinePrecision] * N[(N[Cos[x], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0102:\\
\;\;\;\;\cos x \cdot \left(\cos \varepsilon + -1\right)\\
\mathbf{elif}\;\varepsilon \leq 0.0029:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\cos x \cdot -0.5\right) - \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\end{array}
\end{array}
if eps < -0.010200000000000001Initial program 58.7%
sub-neg58.7%
cos-sum98.5%
associate-+l-98.4%
fma-neg98.4%
Applied egg-rr98.4%
fma-neg98.4%
*-commutative98.4%
*-commutative98.4%
fma-neg98.4%
remove-double-neg98.4%
Simplified98.4%
Taylor expanded in eps around 0 61.8%
sub-neg61.8%
Applied egg-rr61.8%
neg-mul-161.8%
distribute-rgt-out61.8%
+-commutative61.8%
Simplified61.8%
if -0.010200000000000001 < eps < 0.0029Initial program 28.3%
Taylor expanded in eps around 0 98.7%
+-commutative98.7%
mul-1-neg98.7%
unsub-neg98.7%
*-commutative98.7%
associate-*l*98.7%
unpow298.7%
Simplified98.7%
if 0.0029 < eps Initial program 57.9%
Taylor expanded in x around 0 60.4%
Final simplification79.2%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 eps)) (sin (* 0.5 (+ eps (+ x x)))))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * eps)) * sin((0.5 * (eps + (x + 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 + (x + x)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * eps)) * Math.sin((0.5 * (eps + (x + x)))));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * eps)) * math.sin((0.5 * (eps + (x + x)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(Float64(0.5 * Float64(eps + Float64(x + x)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * eps)) * sin((0.5 * (eps + (x + 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[(x + 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 + \left(x + x\right)\right)\right)\right)
\end{array}
Initial program 43.9%
diff-cos52.9%
div-inv52.9%
metadata-eval52.9%
div-inv52.9%
+-commutative52.9%
metadata-eval52.9%
Applied egg-rr52.9%
*-commutative52.9%
+-commutative52.9%
associate--l+78.1%
+-inverses78.1%
distribute-lft-in78.1%
metadata-eval78.1%
*-commutative78.1%
associate-+r+78.1%
+-commutative78.1%
Simplified78.1%
Final simplification78.1%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0102) (not (<= eps 0.0029))) (- (cos eps) (cos x)) (* -2.0 (* (* 0.5 eps) (sin (* 0.5 (+ eps (+ x x))))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0102) || !(eps <= 0.0029)) {
tmp = cos(eps) - cos(x);
} 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 ((eps <= (-0.0102d0)) .or. (.not. (eps <= 0.0029d0))) then
tmp = cos(eps) - cos(x)
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 ((eps <= -0.0102) || !(eps <= 0.0029)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = -2.0 * ((0.5 * eps) * Math.sin((0.5 * (eps + (x + x)))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0102) or not (eps <= 0.0029): tmp = math.cos(eps) - math.cos(x) else: tmp = -2.0 * ((0.5 * eps) * math.sin((0.5 * (eps + (x + x))))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0102) || !(eps <= 0.0029)) tmp = Float64(cos(eps) - cos(x)); 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 ((eps <= -0.0102) || ~((eps <= 0.0029))) tmp = cos(eps) - cos(x); else tmp = -2.0 * ((0.5 * eps) * sin((0.5 * (eps + (x + x))))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0102], N[Not[LessEqual[eps, 0.0029]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $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}\;\varepsilon \leq -0.0102 \lor \neg \left(\varepsilon \leq 0.0029\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\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 eps < -0.010200000000000001 or 0.0029 < eps Initial program 58.3%
Taylor expanded in x around 0 60.8%
if -0.010200000000000001 < eps < 0.0029Initial program 28.3%
diff-cos47.6%
div-inv47.6%
metadata-eval47.6%
div-inv47.6%
+-commutative47.6%
metadata-eval47.6%
Applied egg-rr47.6%
*-commutative47.6%
+-commutative47.6%
associate--l+98.5%
+-inverses98.5%
distribute-lft-in98.5%
metadata-eval98.5%
*-commutative98.5%
associate-+r+98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in eps around 0 98.4%
Final simplification78.9%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.0125)
(* (cos x) (+ (cos eps) -1.0))
(if (<= eps 0.0066)
(* -2.0 (* (* 0.5 eps) (sin (* 0.5 (+ eps (+ x x))))))
(- (cos eps) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0125) {
tmp = cos(x) * (cos(eps) + -1.0);
} else if (eps <= 0.0066) {
tmp = -2.0 * ((0.5 * eps) * sin((0.5 * (eps + (x + x)))));
} else {
tmp = cos(eps) - cos(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-0.0125d0)) then
tmp = cos(x) * (cos(eps) + (-1.0d0))
else if (eps <= 0.0066d0) then
tmp = (-2.0d0) * ((0.5d0 * eps) * sin((0.5d0 * (eps + (x + x)))))
else
tmp = cos(eps) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -0.0125) {
tmp = Math.cos(x) * (Math.cos(eps) + -1.0);
} else if (eps <= 0.0066) {
tmp = -2.0 * ((0.5 * eps) * Math.sin((0.5 * (eps + (x + x)))));
} else {
tmp = Math.cos(eps) - Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.0125: tmp = math.cos(x) * (math.cos(eps) + -1.0) elif eps <= 0.0066: tmp = -2.0 * ((0.5 * eps) * math.sin((0.5 * (eps + (x + x))))) else: tmp = math.cos(eps) - math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.0125) tmp = Float64(cos(x) * Float64(cos(eps) + -1.0)); elseif (eps <= 0.0066) tmp = Float64(-2.0 * Float64(Float64(0.5 * eps) * sin(Float64(0.5 * Float64(eps + Float64(x + x)))))); else tmp = Float64(cos(eps) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -0.0125) tmp = cos(x) * (cos(eps) + -1.0); elseif (eps <= 0.0066) tmp = -2.0 * ((0.5 * eps) * sin((0.5 * (eps + (x + x))))); else tmp = cos(eps) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.0125], N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.0066], 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], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0125:\\
\;\;\;\;\cos x \cdot \left(\cos \varepsilon + -1\right)\\
\mathbf{elif}\;\varepsilon \leq 0.0066:\\
\;\;\;\;-2 \cdot \left(\left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\end{array}
\end{array}
if eps < -0.012500000000000001Initial program 58.7%
sub-neg58.7%
cos-sum98.5%
associate-+l-98.4%
fma-neg98.4%
Applied egg-rr98.4%
fma-neg98.4%
*-commutative98.4%
*-commutative98.4%
fma-neg98.4%
remove-double-neg98.4%
Simplified98.4%
Taylor expanded in eps around 0 61.8%
sub-neg61.8%
Applied egg-rr61.8%
neg-mul-161.8%
distribute-rgt-out61.8%
+-commutative61.8%
Simplified61.8%
if -0.012500000000000001 < eps < 0.0066Initial program 28.3%
diff-cos47.6%
div-inv47.6%
metadata-eval47.6%
div-inv47.6%
+-commutative47.6%
metadata-eval47.6%
Applied egg-rr47.6%
*-commutative47.6%
+-commutative47.6%
associate--l+98.5%
+-inverses98.5%
distribute-lft-in98.5%
metadata-eval98.5%
*-commutative98.5%
associate-+r+98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in eps around 0 98.4%
if 0.0066 < eps Initial program 57.9%
Taylor expanded in x around 0 60.4%
Final simplification79.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0102) (not (<= eps 0.00186))) (+ (cos eps) -1.0) (* -2.0 (* (* 0.5 eps) (sin (* 0.5 (+ eps (+ x x))))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0102) || !(eps <= 0.00186)) {
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 ((eps <= (-0.0102d0)) .or. (.not. (eps <= 0.00186d0))) 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 ((eps <= -0.0102) || !(eps <= 0.00186)) {
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 (eps <= -0.0102) or not (eps <= 0.00186): 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 ((eps <= -0.0102) || !(eps <= 0.00186)) 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 ((eps <= -0.0102) || ~((eps <= 0.00186))) 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[Or[LessEqual[eps, -0.0102], N[Not[LessEqual[eps, 0.00186]], $MachinePrecision]], 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}\;\varepsilon \leq -0.0102 \lor \neg \left(\varepsilon \leq 0.00186\right):\\
\;\;\;\;\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 eps < -0.010200000000000001 or 0.0018600000000000001 < eps Initial program 58.3%
Taylor expanded in x around 0 58.8%
if -0.010200000000000001 < eps < 0.0018600000000000001Initial program 28.3%
diff-cos47.6%
div-inv47.6%
metadata-eval47.6%
div-inv47.6%
+-commutative47.6%
metadata-eval47.6%
Applied egg-rr47.6%
*-commutative47.6%
+-commutative47.6%
associate--l+98.5%
+-inverses98.5%
distribute-lft-in98.5%
metadata-eval98.5%
*-commutative98.5%
associate-+r+98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in eps around 0 98.4%
Final simplification77.8%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0102) (not (<= eps 8.6e-8))) (+ (cos eps) -1.0) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0102) || !(eps <= 8.6e-8)) {
tmp = cos(eps) + -1.0;
} else {
tmp = sin(x) * -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.0102d0)) .or. (.not. (eps <= 8.6d-8))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0102) || !(eps <= 8.6e-8)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0102) or not (eps <= 8.6e-8): tmp = math.cos(eps) + -1.0 else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0102) || !(eps <= 8.6e-8)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0102) || ~((eps <= 8.6e-8))) tmp = cos(eps) + -1.0; else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0102], N[Not[LessEqual[eps, 8.6e-8]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0102 \lor \neg \left(\varepsilon \leq 8.6 \cdot 10^{-8}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -0.010200000000000001 or 8.6000000000000002e-8 < eps Initial program 57.8%
Taylor expanded in x around 0 58.3%
if -0.010200000000000001 < eps < 8.6000000000000002e-8Initial program 28.2%
Taylor expanded in eps around 0 80.7%
mul-1-neg80.7%
*-commutative80.7%
distribute-rgt-neg-in80.7%
Simplified80.7%
Final simplification68.8%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.00018) (not (<= eps 0.000136))) (+ (cos eps) -1.0) (* -0.5 (* eps eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00018) || !(eps <= 0.000136)) {
tmp = cos(eps) + -1.0;
} 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.00018d0)) .or. (.not. (eps <= 0.000136d0))) then
tmp = cos(eps) + (-1.0d0)
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.00018) || !(eps <= 0.000136)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00018) or not (eps <= 0.000136): tmp = math.cos(eps) + -1.0 else: tmp = -0.5 * (eps * eps) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00018) || !(eps <= 0.000136)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(-0.5 * Float64(eps * eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00018) || ~((eps <= 0.000136))) tmp = cos(eps) + -1.0; else tmp = -0.5 * (eps * eps); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00018], N[Not[LessEqual[eps, 0.000136]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00018 \lor \neg \left(\varepsilon \leq 0.000136\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.80000000000000011e-4 or 1.36e-4 < eps Initial program 57.5%
Taylor expanded in x around 0 57.9%
if -1.80000000000000011e-4 < eps < 1.36e-4Initial program 28.8%
Taylor expanded in x around 0 28.8%
Taylor expanded in eps around 0 47.4%
*-commutative47.4%
unpow247.4%
Simplified47.4%
Final simplification53.0%
(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 43.9%
Taylor expanded in x around 0 44.1%
Taylor expanded in eps around 0 24.3%
*-commutative24.3%
unpow224.3%
Simplified24.3%
Final simplification24.3%
(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 43.9%
diff-cos52.9%
div-inv52.9%
metadata-eval52.9%
div-inv52.9%
+-commutative52.9%
metadata-eval52.9%
Applied egg-rr52.9%
*-commutative52.9%
+-commutative52.9%
associate--l+78.1%
+-inverses78.1%
distribute-lft-in78.1%
metadata-eval78.1%
*-commutative78.1%
associate-+r+78.1%
+-commutative78.1%
Simplified78.1%
distribute-lft-in78.1%
sin-sum99.4%
Applied egg-rr99.4%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.4%
*-commutative99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
distribute-lft-neg-in99.4%
metadata-eval99.4%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
Applied egg-rr14.9%
Final simplification14.9%
herbie shell --seed 2023293
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))