
(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 14 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 (* -2.0 (* (sin (* 0.5 (+ eps (- x x)))) (fma (sin (* 0.5 eps)) (cos x) (* (cos (* 0.5 eps)) (sin x))))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * (eps + (x - x)))) * fma(sin((0.5 * eps)), cos(x), (cos((0.5 * eps)) * sin(x))));
}
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * Float64(eps + Float64(x - x)))) * fma(sin(Float64(0.5 * eps)), cos(x), Float64(cos(Float64(0.5 * eps)) * sin(x))))) end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \left(\varepsilon + \left(x - x\right)\right)\right) \cdot \mathsf{fma}\left(\sin \left(0.5 \cdot \varepsilon\right), \cos x, \cos \left(0.5 \cdot \varepsilon\right) \cdot \sin x\right)\right)
\end{array}
Initial program 35.8%
diff-cos44.5%
div-inv44.5%
metadata-eval44.5%
div-inv44.5%
+-commutative44.5%
metadata-eval44.5%
Applied egg-rr44.5%
*-commutative44.5%
+-commutative44.5%
associate--l+76.1%
*-commutative76.1%
associate-+r+76.3%
+-commutative76.3%
Simplified76.3%
log1p-expm1-u76.2%
Applied egg-rr76.2%
log1p-expm1-u76.3%
distribute-lft-in76.3%
*-commutative76.3%
sin-sum99.5%
*-commutative99.5%
*-commutative99.5%
Applied egg-rr99.5%
fma-def99.5%
distribute-rgt-in99.5%
distribute-lft-out99.5%
metadata-eval99.5%
distribute-rgt-in99.5%
distribute-lft-out99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* 0.5 (+ x x))))
(*
-2.0
(*
(sin (* 0.5 (+ eps (- x x))))
(+ (* (sin (* 0.5 eps)) (cos t_0)) (* (cos (* 0.5 eps)) (sin t_0)))))))
double code(double x, double eps) {
double t_0 = 0.5 * (x + x);
return -2.0 * (sin((0.5 * (eps + (x - x)))) * ((sin((0.5 * eps)) * cos(t_0)) + (cos((0.5 * eps)) * sin(t_0))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = 0.5d0 * (x + x)
code = (-2.0d0) * (sin((0.5d0 * (eps + (x - x)))) * ((sin((0.5d0 * eps)) * cos(t_0)) + (cos((0.5d0 * eps)) * sin(t_0))))
end function
public static double code(double x, double eps) {
double t_0 = 0.5 * (x + x);
return -2.0 * (Math.sin((0.5 * (eps + (x - x)))) * ((Math.sin((0.5 * eps)) * Math.cos(t_0)) + (Math.cos((0.5 * eps)) * Math.sin(t_0))));
}
def code(x, eps): t_0 = 0.5 * (x + x) return -2.0 * (math.sin((0.5 * (eps + (x - x)))) * ((math.sin((0.5 * eps)) * math.cos(t_0)) + (math.cos((0.5 * eps)) * math.sin(t_0))))
function code(x, eps) t_0 = Float64(0.5 * Float64(x + x)) return Float64(-2.0 * Float64(sin(Float64(0.5 * Float64(eps + Float64(x - x)))) * Float64(Float64(sin(Float64(0.5 * eps)) * cos(t_0)) + Float64(cos(Float64(0.5 * eps)) * sin(t_0))))) end
function tmp = code(x, eps) t_0 = 0.5 * (x + x); tmp = -2.0 * (sin((0.5 * (eps + (x - x)))) * ((sin((0.5 * eps)) * cos(t_0)) + (cos((0.5 * eps)) * sin(t_0)))); end
code[x_, eps_] := Block[{t$95$0 = N[(0.5 * N[(x + x), $MachinePrecision]), $MachinePrecision]}, N[(-2.0 * N[(N[Sin[N[(0.5 * N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[(N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(x + x\right)\\
-2 \cdot \left(\sin \left(0.5 \cdot \left(\varepsilon + \left(x - x\right)\right)\right) \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \cos t_0 + \cos \left(0.5 \cdot \varepsilon\right) \cdot \sin t_0\right)\right)
\end{array}
\end{array}
Initial program 35.8%
diff-cos44.5%
div-inv44.5%
metadata-eval44.5%
div-inv44.5%
+-commutative44.5%
metadata-eval44.5%
Applied egg-rr44.5%
*-commutative44.5%
+-commutative44.5%
associate--l+76.1%
*-commutative76.1%
associate-+r+76.3%
+-commutative76.3%
Simplified76.3%
log1p-expm1-u76.2%
Applied egg-rr76.2%
log1p-expm1-u76.3%
distribute-rgt-in76.3%
sin-sum99.5%
*-commutative99.5%
*-commutative99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.000145)
(fma (sin x) (- (sin eps)) (* (cos x) (+ -1.0 (cos eps))))
(if (<= eps 0.00015)
(fma
(sin x)
(fma (pow eps 3.0) 0.16666666666666666 (- eps))
(* (cos x) (* eps (* eps -0.5))))
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps)))))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.000145) {
tmp = fma(sin(x), -sin(eps), (cos(x) * (-1.0 + cos(eps))));
} else if (eps <= 0.00015) {
tmp = fma(sin(x), fma(pow(eps, 3.0), 0.16666666666666666, -eps), (cos(x) * (eps * (eps * -0.5))));
} else {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.000145) tmp = fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(-1.0 + cos(eps)))); elseif (eps <= 0.00015) tmp = fma(sin(x), fma((eps ^ 3.0), 0.16666666666666666, Float64(-eps)), Float64(cos(x) * Float64(eps * Float64(eps * -0.5)))); 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.000145], 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.00015], N[(N[Sin[x], $MachinePrecision] * N[(N[Power[eps, 3.0], $MachinePrecision] * 0.16666666666666666 + (-eps)), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(eps * N[(eps * -0.5), $MachinePrecision]), $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.000145:\\
\;\;\;\;\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00015:\\
\;\;\;\;\mathsf{fma}\left(\sin x, \mathsf{fma}\left({\varepsilon}^{3}, 0.16666666666666666, -\varepsilon\right), \cos x \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.45e-4Initial program 44.4%
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%
associate--l+98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
fma-def98.8%
*-rgt-identity98.8%
distribute-lft-out--98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
Simplified98.8%
if -1.45e-4 < eps < 1.49999999999999987e-4Initial program 26.2%
expm1-log1p-u26.2%
Applied egg-rr26.2%
Taylor expanded in eps around 0 99.8%
fma-def99.8%
unpow299.8%
associate-*r*99.8%
fma-def99.8%
+-commutative99.8%
associate-+r+99.8%
+-commutative99.8%
mul-1-neg99.8%
distribute-lft-neg-out99.8%
associate-*r*99.8%
distribute-rgt-in99.8%
Simplified99.8%
if 1.49999999999999987e-4 < eps Initial program 50.3%
cos-sum98.5%
associate--l-98.6%
fma-neg98.6%
fma-def98.7%
Applied egg-rr98.7%
Taylor expanded in x around -inf 98.6%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.000145)
(fma (sin x) (- (sin eps)) (* (cos x) (+ -1.0 (cos eps))))
(if (<= eps 0.00015)
(+
(* -0.5 (* eps (* eps (cos x))))
(* (sin x) (- (* (pow eps 3.0) 0.16666666666666666) eps)))
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps)))))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.000145) {
tmp = fma(sin(x), -sin(eps), (cos(x) * (-1.0 + cos(eps))));
} else if (eps <= 0.00015) {
tmp = (-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((pow(eps, 3.0) * 0.16666666666666666) - 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.000145) tmp = fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(-1.0 + cos(eps)))); elseif (eps <= 0.00015) tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) + Float64(sin(x) * Float64(Float64((eps ^ 3.0) * 0.16666666666666666) - 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.000145], 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.00015], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(N[Power[eps, 3.0], $MachinePrecision] * 0.16666666666666666), $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.000145:\\
\;\;\;\;\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00015:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) + \sin x \cdot \left({\varepsilon}^{3} \cdot 0.16666666666666666 - \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.45e-4Initial program 44.4%
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%
associate--l+98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
fma-def98.8%
*-rgt-identity98.8%
distribute-lft-out--98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
Simplified98.8%
if -1.45e-4 < eps < 1.49999999999999987e-4Initial program 26.2%
Taylor expanded in eps around 0 99.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 1.49999999999999987e-4 < eps Initial program 50.3%
cos-sum98.5%
associate--l-98.6%
fma-neg98.6%
fma-def98.7%
Applied egg-rr98.7%
Taylor expanded in x around -inf 98.6%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.000145) (not (<= eps 0.00015)))
(fma (sin x) (- (sin eps)) (* (cos x) (+ -1.0 (cos eps))))
(+
(* -0.5 (* eps (* eps (cos x))))
(* (sin x) (- (* (pow eps 3.0) 0.16666666666666666) eps)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000145) || !(eps <= 0.00015)) {
tmp = fma(sin(x), -sin(eps), (cos(x) * (-1.0 + cos(eps))));
} else {
tmp = (-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((pow(eps, 3.0) * 0.16666666666666666) - eps));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -0.000145) || !(eps <= 0.00015)) 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((eps ^ 3.0) * 0.16666666666666666) - eps))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000145], N[Not[LessEqual[eps, 0.00015]], $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[(N[Power[eps, 3.0], $MachinePrecision] * 0.16666666666666666), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000145 \lor \neg \left(\varepsilon \leq 0.00015\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({\varepsilon}^{3} \cdot 0.16666666666666666 - \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.45e-4 or 1.49999999999999987e-4 < eps Initial program 47.4%
cos-sum98.6%
cancel-sign-sub-inv98.6%
fma-def98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.6%
neg-mul-198.6%
associate--l+98.8%
*-commutative98.8%
distribute-rgt-neg-in98.8%
fma-def98.7%
*-rgt-identity98.7%
distribute-lft-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
Simplified98.7%
if -1.45e-4 < eps < 1.49999999999999987e-4Initial program 26.2%
Taylor expanded in eps around 0 99.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%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -1e-14) (* -2.0 (pow (sin (* 0.5 eps)) 2.0)) (- (* -0.5 (* eps (* eps (cos x)))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -1e-14) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
} 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 ((cos((eps + x)) - cos(x)) <= (-1d-14)) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
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 ((Math.cos((eps + x)) - Math.cos(x)) <= -1e-14) {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
} else {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -1e-14: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) else: tmp = (-0.5 * (eps * (eps * math.cos(x)))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -1e-14) tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); 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 ((cos((eps + x)) - cos(x)) <= -1e-14) tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); else tmp = (-0.5 * (eps * (eps * cos(x)))) - (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], -1e-14], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $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}\;\cos \left(\varepsilon + x\right) - \cos x \leq -1 \cdot 10^{-14}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.99999999999999999e-15Initial program 69.1%
diff-cos70.8%
div-inv70.8%
metadata-eval70.8%
div-inv70.8%
+-commutative70.8%
metadata-eval70.8%
Applied egg-rr70.8%
*-commutative70.8%
+-commutative70.8%
associate--l+70.8%
*-commutative70.8%
associate-+r+70.8%
+-commutative70.8%
Simplified70.8%
Taylor expanded in x around 0 70.8%
if -9.99999999999999999e-15 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 21.8%
Taylor expanded in eps around 0 77.5%
mul-1-neg77.5%
unsub-neg77.5%
unpow277.5%
associate-*l*77.5%
Simplified77.5%
Final simplification75.5%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -1e-14) (* -2.0 (pow (sin (* 0.5 eps)) 2.0)) (* (sin x) (* -2.0 (sin (/ eps 2.0))))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -1e-14) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
} else {
tmp = sin(x) * (-2.0 * sin((eps / 2.0)));
}
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)) <= (-1d-14)) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
else
tmp = sin(x) * ((-2.0d0) * sin((eps / 2.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -1e-14) {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
} else {
tmp = Math.sin(x) * (-2.0 * Math.sin((eps / 2.0)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -1e-14: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) else: tmp = math.sin(x) * (-2.0 * math.sin((eps / 2.0))) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -1e-14) tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); else tmp = Float64(sin(x) * Float64(-2.0 * sin(Float64(eps / 2.0)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -1e-14) tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); else tmp = sin(x) * (-2.0 * sin((eps / 2.0))); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -1e-14], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -1 \cdot 10^{-14}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-2 \cdot \sin \left(\frac{\varepsilon}{2}\right)\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.99999999999999999e-15Initial program 69.1%
diff-cos70.8%
div-inv70.8%
metadata-eval70.8%
div-inv70.8%
+-commutative70.8%
metadata-eval70.8%
Applied egg-rr70.8%
*-commutative70.8%
+-commutative70.8%
associate--l+70.8%
*-commutative70.8%
associate-+r+70.8%
+-commutative70.8%
Simplified70.8%
Taylor expanded in x around 0 70.8%
if -9.99999999999999999e-15 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 21.8%
expm1-log1p-u21.8%
Applied egg-rr21.8%
expm1-log1p-u21.8%
diff-cos33.4%
+-commutative33.4%
associate-+r-78.4%
+-inverses78.4%
+-commutative78.4%
associate-+r+78.6%
Applied egg-rr78.6%
associate-*r*78.6%
+-rgt-identity78.6%
Simplified78.6%
Taylor expanded in eps around 0 67.6%
Final simplification68.5%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -1e-14) (* -2.0 (pow (sin (* 0.5 eps)) 2.0)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -1e-14) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.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 ((cos((eps + x)) - cos(x)) <= (-1d-14)) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
else
tmp = 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)) <= -1e-14) {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -1e-14: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -1e-14) tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -1e-14) tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); else tmp = 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], -1e-14], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -1 \cdot 10^{-14}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.99999999999999999e-15Initial program 69.1%
diff-cos70.8%
div-inv70.8%
metadata-eval70.8%
div-inv70.8%
+-commutative70.8%
metadata-eval70.8%
Applied egg-rr70.8%
*-commutative70.8%
+-commutative70.8%
associate--l+70.8%
*-commutative70.8%
associate-+r+70.8%
+-commutative70.8%
Simplified70.8%
Taylor expanded in x around 0 70.8%
if -9.99999999999999999e-15 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 21.8%
Taylor expanded in eps around 0 66.1%
associate-*r*65.2%
mul-1-neg65.2%
Simplified66.1%
Final simplification67.5%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -1e-14) (+ -1.0 (* (cos x) (cos eps))) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -1e-14) {
tmp = -1.0 + (cos(x) * cos(eps));
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((cos((eps + x)) - cos(x)) <= (-1d-14)) then
tmp = (-1.0d0) + (cos(x) * cos(eps))
else
tmp = 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)) <= -1e-14) {
tmp = -1.0 + (Math.cos(x) * Math.cos(eps));
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -1e-14: tmp = -1.0 + (math.cos(x) * math.cos(eps)) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -1e-14) tmp = Float64(-1.0 + Float64(cos(x) * cos(eps))); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -1e-14) tmp = -1.0 + (cos(x) * cos(eps)); else tmp = 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], -1e-14], N[(-1.0 + N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -1 \cdot 10^{-14}:\\
\;\;\;\;-1 + \cos x \cdot \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.99999999999999999e-15Initial program 69.1%
cos-sum97.6%
associate--l-97.7%
fma-neg97.7%
fma-def97.7%
Applied egg-rr97.7%
Taylor expanded in x around 0 69.2%
Taylor expanded in x around -inf 69.2%
if -9.99999999999999999e-15 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 21.8%
Taylor expanded in eps around 0 66.1%
associate-*r*65.2%
mul-1-neg65.2%
Simplified66.1%
Final simplification67.0%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -1e-14) (+ -1.0 (cos eps)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -1e-14) {
tmp = -1.0 + cos(eps);
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((cos((eps + x)) - cos(x)) <= (-1d-14)) then
tmp = (-1.0d0) + cos(eps)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -1e-14) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -1e-14: tmp = -1.0 + math.cos(eps) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -1e-14) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -1e-14) tmp = -1.0 + cos(eps); else tmp = 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], -1e-14], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -1 \cdot 10^{-14}:\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.99999999999999999e-15Initial program 69.1%
Taylor expanded in x around 0 69.2%
if -9.99999999999999999e-15 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 21.8%
Taylor expanded in eps around 0 66.1%
associate-*r*65.2%
mul-1-neg65.2%
Simplified66.1%
Final simplification67.0%
(FPCore (x eps) :precision binary64 (* (* -2.0 (sin (/ eps 2.0))) (sin (/ (+ eps (+ x x)) 2.0))))
double code(double x, double eps) {
return (-2.0 * sin((eps / 2.0))) * sin(((eps + (x + x)) / 2.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((-2.0d0) * sin((eps / 2.0d0))) * sin(((eps + (x + x)) / 2.0d0))
end function
public static double code(double x, double eps) {
return (-2.0 * Math.sin((eps / 2.0))) * Math.sin(((eps + (x + x)) / 2.0));
}
def code(x, eps): return (-2.0 * math.sin((eps / 2.0))) * math.sin(((eps + (x + x)) / 2.0))
function code(x, eps) return Float64(Float64(-2.0 * sin(Float64(eps / 2.0))) * sin(Float64(Float64(eps + Float64(x + x)) / 2.0))) end
function tmp = code(x, eps) tmp = (-2.0 * sin((eps / 2.0))) * sin(((eps + (x + x)) / 2.0)); end
code[x_, eps_] := N[(N[(-2.0 * N[Sin[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-2 \cdot \sin \left(\frac{\varepsilon}{2}\right)\right) \cdot \sin \left(\frac{\varepsilon + \left(x + x\right)}{2}\right)
\end{array}
Initial program 35.8%
expm1-log1p-u26.3%
Applied egg-rr26.3%
expm1-log1p-u35.8%
diff-cos44.5%
+-commutative44.5%
associate-+r-76.1%
+-inverses76.1%
+-commutative76.1%
associate-+r+76.3%
Applied egg-rr76.3%
associate-*r*76.3%
+-rgt-identity76.3%
Simplified76.3%
Final simplification76.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.8e-7) (not (<= eps 0.00015))) (+ -1.0 (cos eps)) (* -0.5 (* eps eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.8e-7) || !(eps <= 0.00015)) {
tmp = -1.0 + cos(eps);
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-3.8d-7)) .or. (.not. (eps <= 0.00015d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = (-0.5d0) * (eps * eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -3.8e-7) || !(eps <= 0.00015)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.8e-7) or not (eps <= 0.00015): tmp = -1.0 + math.cos(eps) else: tmp = -0.5 * (eps * eps) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.8e-7) || !(eps <= 0.00015)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(-0.5 * Float64(eps * eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -3.8e-7) || ~((eps <= 0.00015))) tmp = -1.0 + cos(eps); else tmp = -0.5 * (eps * eps); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.8e-7], N[Not[LessEqual[eps, 0.00015]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.8 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 0.00015\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\end{array}
\end{array}
if eps < -3.80000000000000015e-7 or 1.49999999999999987e-4 < eps Initial program 46.6%
Taylor expanded in x around 0 48.6%
if -3.80000000000000015e-7 < eps < 1.49999999999999987e-4Initial program 26.6%
Taylor expanded in x around 0 26.5%
Taylor expanded in eps around 0 39.5%
*-commutative39.5%
unpow239.5%
Simplified39.5%
Final simplification43.7%
(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 35.8%
Taylor expanded in x around 0 36.7%
Taylor expanded in eps around 0 23.2%
*-commutative23.2%
unpow223.2%
Simplified23.2%
Final simplification23.2%
(FPCore (x eps) :precision binary64 (* eps x))
double code(double x, double eps) {
return eps * x;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * x
end function
public static double code(double x, double eps) {
return eps * x;
}
def code(x, eps): return eps * x
function code(x, eps) return Float64(eps * x) end
function tmp = code(x, eps) tmp = eps * x; end
code[x_, eps_] := N[(eps * x), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot x
\end{array}
Initial program 35.8%
add-cube-cbrt35.6%
pow335.6%
Applied egg-rr35.6%
Taylor expanded in eps around 0 46.9%
associate-*r*46.9%
mul-1-neg46.9%
Simplified46.9%
rem-cube-cbrt47.6%
expm1-log1p-u46.8%
expm1-udef15.5%
rem-cube-cbrt15.5%
rem-cube-cbrt15.5%
add-sqr-sqrt8.0%
sqrt-unprod15.2%
sqr-neg15.2%
sqrt-unprod7.3%
add-sqr-sqrt14.9%
Applied egg-rr14.9%
expm1-def14.6%
expm1-log1p15.1%
*-commutative15.1%
Simplified15.1%
Taylor expanded in x around 0 15.0%
*-commutative15.0%
Simplified15.0%
Final simplification15.0%
herbie shell --seed 2023238
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))