
(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 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5)))
(t_1 (+ (cos eps) -1.0))
(t_2 (* (sin x) (sin eps))))
(if (<= x -1.9e-8)
(- (* (cos x) (log (exp t_1))) t_2)
(if (<= x 1.6e-50)
(* (+ t_0 (* x (cos (* eps 0.5)))) (* t_0 -2.0))
(- (* (cos x) t_1) t_2)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double t_1 = cos(eps) + -1.0;
double t_2 = sin(x) * sin(eps);
double tmp;
if (x <= -1.9e-8) {
tmp = (cos(x) * log(exp(t_1))) - t_2;
} else if (x <= 1.6e-50) {
tmp = (t_0 + (x * cos((eps * 0.5)))) * (t_0 * -2.0);
} else {
tmp = (cos(x) * t_1) - t_2;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = sin((eps * 0.5d0))
t_1 = cos(eps) + (-1.0d0)
t_2 = sin(x) * sin(eps)
if (x <= (-1.9d-8)) then
tmp = (cos(x) * log(exp(t_1))) - t_2
else if (x <= 1.6d-50) then
tmp = (t_0 + (x * cos((eps * 0.5d0)))) * (t_0 * (-2.0d0))
else
tmp = (cos(x) * t_1) - t_2
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
double t_1 = Math.cos(eps) + -1.0;
double t_2 = Math.sin(x) * Math.sin(eps);
double tmp;
if (x <= -1.9e-8) {
tmp = (Math.cos(x) * Math.log(Math.exp(t_1))) - t_2;
} else if (x <= 1.6e-50) {
tmp = (t_0 + (x * Math.cos((eps * 0.5)))) * (t_0 * -2.0);
} else {
tmp = (Math.cos(x) * t_1) - t_2;
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) t_1 = math.cos(eps) + -1.0 t_2 = math.sin(x) * math.sin(eps) tmp = 0 if x <= -1.9e-8: tmp = (math.cos(x) * math.log(math.exp(t_1))) - t_2 elif x <= 1.6e-50: tmp = (t_0 + (x * math.cos((eps * 0.5)))) * (t_0 * -2.0) else: tmp = (math.cos(x) * t_1) - t_2 return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) t_1 = Float64(cos(eps) + -1.0) t_2 = Float64(sin(x) * sin(eps)) tmp = 0.0 if (x <= -1.9e-8) tmp = Float64(Float64(cos(x) * log(exp(t_1))) - t_2); elseif (x <= 1.6e-50) tmp = Float64(Float64(t_0 + Float64(x * cos(Float64(eps * 0.5)))) * Float64(t_0 * -2.0)); else tmp = Float64(Float64(cos(x) * t_1) - t_2); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); t_1 = cos(eps) + -1.0; t_2 = sin(x) * sin(eps); tmp = 0.0; if (x <= -1.9e-8) tmp = (cos(x) * log(exp(t_1))) - t_2; elseif (x <= 1.6e-50) tmp = (t_0 + (x * cos((eps * 0.5)))) * (t_0 * -2.0); else tmp = (cos(x) * t_1) - t_2; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.9e-8], N[(N[(N[Cos[x], $MachinePrecision] * N[Log[N[Exp[t$95$1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision], If[LessEqual[x, 1.6e-50], N[(N[(t$95$0 + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * t$95$1), $MachinePrecision] - t$95$2), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
t_1 := \cos \varepsilon + -1\\
t_2 := \sin x \cdot \sin \varepsilon\\
\mathbf{if}\;x \leq -1.9 \cdot 10^{-8}:\\
\;\;\;\;\cos x \cdot \log \left(e^{t_1}\right) - t_2\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-50}:\\
\;\;\;\;\left(t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(t_0 \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot t_1 - t_2\\
\end{array}
\end{array}
if x < -1.90000000000000014e-8Initial program 7.9%
sub-neg7.9%
+-commutative7.9%
cos-sum50.2%
sub-neg50.2%
associate-+r+98.6%
distribute-rgt-neg-in98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.6%
fma-neg98.7%
fma-def98.6%
neg-mul-198.6%
distribute-rgt-out98.7%
Simplified98.7%
add-log-exp_binary6498.7%
Applied rewrite-once98.7%
if -1.90000000000000014e-8 < x < 1.6e-50Initial program 71.6%
diff-cos92.4%
div-inv92.4%
+-commutative92.4%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
div-inv99.3%
+-commutative99.3%
metadata-eval99.3%
Applied egg-rr99.3%
associate-*r*99.4%
*-commutative99.4%
*-commutative99.4%
associate-+r+99.4%
+-commutative99.4%
+-rgt-identity99.4%
Simplified99.4%
Taylor expanded in x around 0 99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
if 1.6e-50 < x Initial program 13.7%
sub-neg13.7%
+-commutative13.7%
cos-sum46.0%
sub-neg46.0%
associate-+r+99.3%
distribute-rgt-neg-in99.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 99.3%
fma-neg99.3%
fma-def99.3%
neg-mul-199.3%
distribute-rgt-out99.3%
Simplified99.3%
Taylor expanded in x around inf 99.3%
+-commutative99.3%
sub-neg99.3%
metadata-eval99.3%
mul-1-neg99.3%
unsub-neg99.3%
Simplified99.3%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))) (t_1 (+ (cos eps) -1.0)))
(if (<= x -3.2e-10)
(fma (cos x) t_1 (* (sin eps) (- (sin x))))
(if (<= x 9.5e-55)
(* (+ t_0 (* x (cos (* eps 0.5)))) (* t_0 -2.0))
(- (* (cos x) t_1) (* (sin x) (sin eps)))))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double t_1 = cos(eps) + -1.0;
double tmp;
if (x <= -3.2e-10) {
tmp = fma(cos(x), t_1, (sin(eps) * -sin(x)));
} else if (x <= 9.5e-55) {
tmp = (t_0 + (x * cos((eps * 0.5)))) * (t_0 * -2.0);
} else {
tmp = (cos(x) * t_1) - (sin(x) * sin(eps));
}
return tmp;
}
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) t_1 = Float64(cos(eps) + -1.0) tmp = 0.0 if (x <= -3.2e-10) tmp = fma(cos(x), t_1, Float64(sin(eps) * Float64(-sin(x)))); elseif (x <= 9.5e-55) tmp = Float64(Float64(t_0 + Float64(x * cos(Float64(eps * 0.5)))) * Float64(t_0 * -2.0)); else tmp = Float64(Float64(cos(x) * t_1) - Float64(sin(x) * sin(eps))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[x, -3.2e-10], N[(N[Cos[x], $MachinePrecision] * t$95$1 + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9.5e-55], N[(N[(t$95$0 + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * t$95$1), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
t_1 := \cos \varepsilon + -1\\
\mathbf{if}\;x \leq -3.2 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, t_1, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{-55}:\\
\;\;\;\;\left(t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(t_0 \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot t_1 - \sin x \cdot \sin \varepsilon\\
\end{array}
\end{array}
if x < -3.19999999999999981e-10Initial program 7.9%
sub-neg7.9%
+-commutative7.9%
cos-sum50.2%
sub-neg50.2%
associate-+r+98.6%
distribute-rgt-neg-in98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.6%
fma-neg98.7%
fma-def98.6%
neg-mul-198.6%
distribute-rgt-out98.7%
Simplified98.7%
Taylor expanded in x around inf 98.7%
+-commutative98.7%
sub-neg98.7%
metadata-eval98.7%
associate-*r*98.7%
neg-mul-198.7%
*-commutative98.7%
fma-def98.7%
Simplified98.7%
if -3.19999999999999981e-10 < x < 9.5000000000000006e-55Initial program 71.6%
diff-cos92.4%
div-inv92.4%
+-commutative92.4%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
div-inv99.3%
+-commutative99.3%
metadata-eval99.3%
Applied egg-rr99.3%
associate-*r*99.4%
*-commutative99.4%
*-commutative99.4%
associate-+r+99.4%
+-commutative99.4%
+-rgt-identity99.4%
Simplified99.4%
Taylor expanded in x around 0 99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
if 9.5000000000000006e-55 < x Initial program 13.7%
sub-neg13.7%
+-commutative13.7%
cos-sum46.0%
sub-neg46.0%
associate-+r+99.3%
distribute-rgt-neg-in99.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 99.3%
fma-neg99.3%
fma-def99.3%
neg-mul-199.3%
distribute-rgt-out99.3%
Simplified99.3%
Taylor expanded in x around inf 99.3%
+-commutative99.3%
sub-neg99.3%
metadata-eval99.3%
mul-1-neg99.3%
unsub-neg99.3%
Simplified99.3%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ x eps)) (cos x)) -2e-5) (* -2.0 (pow (sin (* eps 0.5)) 2.0)) (- (* (* eps eps) (* (cos x) -0.5)) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((x + eps)) - cos(x)) <= -2e-5) {
tmp = -2.0 * pow(sin((eps * 0.5)), 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((x + eps)) - cos(x)) <= (-2d-5)) then
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 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((x + eps)) - Math.cos(x)) <= -2e-5) {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 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((x + eps)) - math.cos(x)) <= -2e-5: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 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(x + eps)) - cos(x)) <= -2e-5) tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 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((x + eps)) - cos(x)) <= -2e-5) tmp = -2.0 * (sin((eps * 0.5)) ^ 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[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -2e-5], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $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(x + \varepsilon\right) - \cos x \leq -2 \cdot 10^{-5}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\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)) < -2.00000000000000016e-5Initial program 83.8%
diff-cos84.4%
div-inv84.4%
+-commutative84.4%
associate--l+84.0%
+-inverses84.0%
metadata-eval84.0%
div-inv84.0%
+-commutative84.0%
metadata-eval84.0%
Applied egg-rr84.0%
associate-*r*84.0%
*-commutative84.0%
*-commutative84.0%
associate-+r+84.4%
+-commutative84.4%
+-rgt-identity84.4%
Simplified84.4%
Taylor expanded in x around 0 84.5%
*-commutative84.5%
Simplified84.5%
if -2.00000000000000016e-5 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 15.4%
Taylor expanded in eps around 0 76.4%
+-commutative76.4%
mul-1-neg76.4%
unsub-neg76.4%
*-commutative76.4%
associate-*l*76.4%
unpow276.4%
Simplified76.4%
Final simplification79.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -1.9e-8) (not (<= x 1.6e-50)))
(- (* (cos x) (+ (cos eps) -1.0)) (* (sin x) (sin eps)))
(* (+ t_0 (* x (cos (* eps 0.5)))) (* t_0 -2.0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -1.9e-8) || !(x <= 1.6e-50)) {
tmp = (cos(x) * (cos(eps) + -1.0)) - (sin(x) * sin(eps));
} else {
tmp = (t_0 + (x * cos((eps * 0.5)))) * (t_0 * -2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((eps * 0.5d0))
if ((x <= (-1.9d-8)) .or. (.not. (x <= 1.6d-50))) then
tmp = (cos(x) * (cos(eps) + (-1.0d0))) - (sin(x) * sin(eps))
else
tmp = (t_0 + (x * cos((eps * 0.5d0)))) * (t_0 * (-2.0d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
double tmp;
if ((x <= -1.9e-8) || !(x <= 1.6e-50)) {
tmp = (Math.cos(x) * (Math.cos(eps) + -1.0)) - (Math.sin(x) * Math.sin(eps));
} else {
tmp = (t_0 + (x * Math.cos((eps * 0.5)))) * (t_0 * -2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -1.9e-8) or not (x <= 1.6e-50): tmp = (math.cos(x) * (math.cos(eps) + -1.0)) - (math.sin(x) * math.sin(eps)) else: tmp = (t_0 + (x * math.cos((eps * 0.5)))) * (t_0 * -2.0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -1.9e-8) || !(x <= 1.6e-50)) tmp = Float64(Float64(cos(x) * Float64(cos(eps) + -1.0)) - Float64(sin(x) * sin(eps))); else tmp = Float64(Float64(t_0 + Float64(x * cos(Float64(eps * 0.5)))) * Float64(t_0 * -2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -1.9e-8) || ~((x <= 1.6e-50))) tmp = (cos(x) * (cos(eps) + -1.0)) - (sin(x) * sin(eps)); else tmp = (t_0 + (x * cos((eps * 0.5)))) * (t_0 * -2.0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -1.9e-8], N[Not[LessEqual[x, 1.6e-50]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -1.9 \cdot 10^{-8} \lor \neg \left(x \leq 1.6 \cdot 10^{-50}\right):\\
\;\;\;\;\cos x \cdot \left(\cos \varepsilon + -1\right) - \sin x \cdot \sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\left(t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(t_0 \cdot -2\right)\\
\end{array}
\end{array}
if x < -1.90000000000000014e-8 or 1.6e-50 < x Initial program 10.6%
sub-neg10.6%
+-commutative10.6%
cos-sum48.3%
sub-neg48.3%
associate-+r+98.9%
distribute-rgt-neg-in98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 98.9%
fma-neg99.0%
fma-def98.9%
neg-mul-198.9%
distribute-rgt-out99.0%
Simplified99.0%
Taylor expanded in x around inf 99.0%
+-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
mul-1-neg99.0%
unsub-neg99.0%
Simplified99.0%
if -1.90000000000000014e-8 < x < 1.6e-50Initial program 71.6%
diff-cos92.4%
div-inv92.4%
+-commutative92.4%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
div-inv99.3%
+-commutative99.3%
metadata-eval99.3%
Applied egg-rr99.3%
associate-*r*99.4%
*-commutative99.4%
*-commutative99.4%
associate-+r+99.4%
+-commutative99.4%
+-rgt-identity99.4%
Simplified99.4%
Taylor expanded in x around 0 99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ x eps)) (cos x)) -2e-16) (+ (cos eps) -1.0) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((x + eps)) - cos(x)) <= -2e-16) {
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 ((cos((x + eps)) - cos(x)) <= (-2d-16)) 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 ((Math.cos((x + eps)) - Math.cos(x)) <= -2e-16) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((x + eps)) - math.cos(x)) <= -2e-16: tmp = math.cos(eps) + -1.0 else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(x + eps)) - cos(x)) <= -2e-16) 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 ((cos((x + eps)) - cos(x)) <= -2e-16) tmp = cos(eps) + -1.0; else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -2e-16], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(x + \varepsilon\right) - \cos x \leq -2 \cdot 10^{-16}:\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -2e-16Initial program 83.1%
Taylor expanded in x around 0 83.1%
if -2e-16 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 15.4%
Taylor expanded in eps around 0 62.3%
associate-*r*62.3%
*-commutative62.3%
mul-1-neg62.3%
Simplified62.3%
Final simplification69.5%
(FPCore (x eps) :precision binary64 (* (* (sin (* eps 0.5)) -2.0) (sin (* 0.5 (+ eps (+ x x))))))
double code(double x, double eps) {
return (sin((eps * 0.5)) * -2.0) * sin((0.5 * (eps + (x + x))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (sin((eps * 0.5d0)) * (-2.0d0)) * sin((0.5d0 * (eps + (x + x))))
end function
public static double code(double x, double eps) {
return (Math.sin((eps * 0.5)) * -2.0) * Math.sin((0.5 * (eps + (x + x))));
}
def code(x, eps): return (math.sin((eps * 0.5)) * -2.0) * math.sin((0.5 * (eps + (x + x))))
function code(x, eps) return Float64(Float64(sin(Float64(eps * 0.5)) * -2.0) * sin(Float64(0.5 * Float64(eps + Float64(x + x))))) end
function tmp = code(x, eps) tmp = (sin((eps * 0.5)) * -2.0) * sin((0.5 * (eps + (x + x)))); end
code[x_, eps_] := N[(N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * -2.0), $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\sin \left(\varepsilon \cdot 0.5\right) \cdot -2\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)
\end{array}
Initial program 38.9%
diff-cos48.8%
div-inv48.8%
+-commutative48.8%
associate--l+80.3%
+-inverses80.3%
metadata-eval80.3%
div-inv80.3%
+-commutative80.3%
metadata-eval80.3%
Applied egg-rr80.3%
associate-*r*80.3%
*-commutative80.3%
*-commutative80.3%
associate-+r+80.4%
+-commutative80.4%
+-rgt-identity80.4%
Simplified80.4%
Final simplification80.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -3500.0) (not (<= x 4.1e-49)))
(* (sin x) (* t_0 -2.0))
(* -2.0 (pow t_0 2.0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -3500.0) || !(x <= 4.1e-49)) {
tmp = sin(x) * (t_0 * -2.0);
} else {
tmp = -2.0 * pow(t_0, 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((eps * 0.5d0))
if ((x <= (-3500.0d0)) .or. (.not. (x <= 4.1d-49))) then
tmp = sin(x) * (t_0 * (-2.0d0))
else
tmp = (-2.0d0) * (t_0 ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
double tmp;
if ((x <= -3500.0) || !(x <= 4.1e-49)) {
tmp = Math.sin(x) * (t_0 * -2.0);
} else {
tmp = -2.0 * Math.pow(t_0, 2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -3500.0) or not (x <= 4.1e-49): tmp = math.sin(x) * (t_0 * -2.0) else: tmp = -2.0 * math.pow(t_0, 2.0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -3500.0) || !(x <= 4.1e-49)) tmp = Float64(sin(x) * Float64(t_0 * -2.0)); else tmp = Float64(-2.0 * (t_0 ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -3500.0) || ~((x <= 4.1e-49))) tmp = sin(x) * (t_0 * -2.0); else tmp = -2.0 * (t_0 ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -3500.0], N[Not[LessEqual[x, 4.1e-49]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * N[(t$95$0 * -2.0), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -3500 \lor \neg \left(x \leq 4.1 \cdot 10^{-49}\right):\\
\;\;\;\;\sin x \cdot \left(t_0 \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -3500 or 4.1000000000000001e-49 < x Initial program 9.1%
diff-cos9.4%
div-inv9.4%
+-commutative9.4%
associate--l+63.9%
+-inverses63.9%
metadata-eval63.9%
div-inv63.9%
+-commutative63.9%
metadata-eval63.9%
Applied egg-rr63.9%
associate-*r*63.9%
*-commutative63.9%
*-commutative63.9%
associate-+r+64.1%
+-commutative64.1%
+-rgt-identity64.1%
Simplified64.1%
Taylor expanded in eps around 0 61.9%
if -3500 < x < 4.1000000000000001e-49Initial program 70.7%
diff-cos90.7%
div-inv90.7%
+-commutative90.7%
associate--l+97.8%
+-inverses97.8%
metadata-eval97.8%
div-inv97.8%
+-commutative97.8%
metadata-eval97.8%
Applied egg-rr97.8%
associate-*r*97.8%
*-commutative97.8%
*-commutative97.8%
associate-+r+97.8%
+-commutative97.8%
+-rgt-identity97.8%
Simplified97.8%
Taylor expanded in x around 0 89.2%
*-commutative89.2%
Simplified89.2%
Final simplification75.1%
(FPCore (x eps) :precision binary64 (if (or (<= x -8200.0) (not (<= x 4.8e-49))) (* eps (- (sin x))) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -8200.0) || !(x <= 4.8e-49)) {
tmp = eps * -sin(x);
} else {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-8200.0d0)) .or. (.not. (x <= 4.8d-49))) then
tmp = eps * -sin(x)
else
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -8200.0) || !(x <= 4.8e-49)) {
tmp = eps * -Math.sin(x);
} else {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -8200.0) or not (x <= 4.8e-49): tmp = eps * -math.sin(x) else: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -8200.0) || !(x <= 4.8e-49)) tmp = Float64(eps * Float64(-sin(x))); else tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -8200.0) || ~((x <= 4.8e-49))) tmp = eps * -sin(x); else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -8200.0], N[Not[LessEqual[x, 4.8e-49]], $MachinePrecision]], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8200 \lor \neg \left(x \leq 4.8 \cdot 10^{-49}\right):\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if x < -8200 or 4.79999999999999985e-49 < x Initial program 9.2%
Taylor expanded in eps around 0 58.4%
associate-*r*58.4%
*-commutative58.4%
mul-1-neg58.4%
Simplified58.4%
if -8200 < x < 4.79999999999999985e-49Initial program 70.1%
diff-cos90.1%
div-inv90.1%
+-commutative90.1%
associate--l+97.1%
+-inverses97.1%
metadata-eval97.1%
div-inv97.1%
+-commutative97.1%
metadata-eval97.1%
Applied egg-rr97.1%
associate-*r*97.2%
*-commutative97.2%
*-commutative97.2%
associate-+r+97.2%
+-commutative97.2%
+-rgt-identity97.2%
Simplified97.2%
Taylor expanded in x around 0 88.6%
*-commutative88.6%
Simplified88.6%
Final simplification73.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000155) (not (<= eps 0.0106))) (+ (cos eps) -1.0) (* eps (- (* eps -0.5) x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000155) || !(eps <= 0.0106)) {
tmp = cos(eps) + -1.0;
} else {
tmp = eps * ((eps * -0.5) - 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.000155d0)) .or. (.not. (eps <= 0.0106d0))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = eps * ((eps * (-0.5d0)) - x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.000155) || !(eps <= 0.0106)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * ((eps * -0.5) - x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000155) or not (eps <= 0.0106): tmp = math.cos(eps) + -1.0 else: tmp = eps * ((eps * -0.5) - x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000155) || !(eps <= 0.0106)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(eps * Float64(Float64(eps * -0.5) - x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000155) || ~((eps <= 0.0106))) tmp = cos(eps) + -1.0; else tmp = eps * ((eps * -0.5) - x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000155], N[Not[LessEqual[eps, 0.0106]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(eps * N[(N[(eps * -0.5), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000155 \lor \neg \left(\varepsilon \leq 0.0106\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5 - x\right)\\
\end{array}
\end{array}
if eps < -1.55e-4 or 0.0106 < eps Initial program 59.1%
Taylor expanded in x around 0 61.1%
if -1.55e-4 < eps < 0.0106Initial program 18.7%
Taylor expanded in x around 0 18.4%
associate--l+18.4%
associate-*r*18.4%
mul-1-neg18.4%
Simplified18.4%
Taylor expanded in eps around 0 49.1%
+-commutative49.1%
mul-1-neg49.1%
unsub-neg49.1%
*-commutative49.1%
unpow249.1%
associate-*l*49.1%
distribute-lft-out--49.1%
Simplified49.1%
Final simplification55.1%
(FPCore (x eps) :precision binary64 (if (or (<= x -7.2e-132) (not (<= x 7e-71))) (* x (- eps)) (* eps (* eps -0.5))))
double code(double x, double eps) {
double tmp;
if ((x <= -7.2e-132) || !(x <= 7e-71)) {
tmp = x * -eps;
} else {
tmp = eps * (eps * -0.5);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-7.2d-132)) .or. (.not. (x <= 7d-71))) then
tmp = x * -eps
else
tmp = eps * (eps * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -7.2e-132) || !(x <= 7e-71)) {
tmp = x * -eps;
} else {
tmp = eps * (eps * -0.5);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -7.2e-132) or not (x <= 7e-71): tmp = x * -eps else: tmp = eps * (eps * -0.5) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -7.2e-132) || !(x <= 7e-71)) tmp = Float64(x * Float64(-eps)); else tmp = Float64(eps * Float64(eps * -0.5)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -7.2e-132) || ~((x <= 7e-71))) tmp = x * -eps; else tmp = eps * (eps * -0.5); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -7.2e-132], N[Not[LessEqual[x, 7e-71]], $MachinePrecision]], N[(x * (-eps)), $MachinePrecision], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-132} \lor \neg \left(x \leq 7 \cdot 10^{-71}\right):\\
\;\;\;\;x \cdot \left(-\varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\end{array}
\end{array}
if x < -7.20000000000000015e-132 or 6.9999999999999998e-71 < x Initial program 20.1%
Taylor expanded in x around 0 19.0%
associate--l+19.0%
associate-*r*19.0%
mul-1-neg19.0%
Simplified19.0%
Taylor expanded in eps around 0 15.1%
associate-*r*15.1%
mul-1-neg15.1%
Simplified15.1%
if -7.20000000000000015e-132 < x < 6.9999999999999998e-71Initial program 73.0%
Taylor expanded in x around 0 73.0%
Taylor expanded in eps around 0 41.6%
*-commutative41.6%
unpow241.6%
associate-*l*41.6%
Simplified41.6%
Final simplification24.5%
(FPCore (x eps) :precision binary64 (* eps (- (* eps -0.5) x)))
double code(double x, double eps) {
return eps * ((eps * -0.5) - x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * ((eps * (-0.5d0)) - x)
end function
public static double code(double x, double eps) {
return eps * ((eps * -0.5) - x);
}
def code(x, eps): return eps * ((eps * -0.5) - x)
function code(x, eps) return Float64(eps * Float64(Float64(eps * -0.5) - x)) end
function tmp = code(x, eps) tmp = eps * ((eps * -0.5) - x); end
code[x_, eps_] := N[(eps * N[(N[(eps * -0.5), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(\varepsilon \cdot -0.5 - x\right)
\end{array}
Initial program 38.9%
Taylor expanded in x around 0 38.2%
associate--l+38.2%
associate-*r*38.2%
mul-1-neg38.2%
Simplified38.2%
Taylor expanded in eps around 0 26.2%
+-commutative26.2%
mul-1-neg26.2%
unsub-neg26.2%
*-commutative26.2%
unpow226.2%
associate-*l*26.2%
distribute-lft-out--26.3%
Simplified26.3%
Final simplification26.3%
(FPCore (x eps) :precision binary64 (* x (- eps)))
double code(double x, double eps) {
return x * -eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x * -eps
end function
public static double code(double x, double eps) {
return x * -eps;
}
def code(x, eps): return x * -eps
function code(x, eps) return Float64(x * Float64(-eps)) end
function tmp = code(x, eps) tmp = x * -eps; end
code[x_, eps_] := N[(x * (-eps)), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(-\varepsilon\right)
\end{array}
Initial program 38.9%
Taylor expanded in x around 0 38.2%
associate--l+38.2%
associate-*r*38.2%
mul-1-neg38.2%
Simplified38.2%
Taylor expanded in eps around 0 17.0%
associate-*r*17.0%
mul-1-neg17.0%
Simplified17.0%
Final simplification17.0%
herbie shell --seed 2023297
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))