
(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 10 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)))) (* (fma (sin x) (cos (* 0.5 eps)) (* (cos x) t_0)) (* t_0 -2.0))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return fma(sin(x), cos((0.5 * eps)), (cos(x) * t_0)) * (t_0 * -2.0);
}
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(fma(sin(x), cos(Float64(0.5 * eps)), Float64(cos(x) * t_0)) * Float64(t_0 * -2.0)) end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
\mathsf{fma}\left(\sin x, \cos \left(0.5 \cdot \varepsilon\right), \cos x \cdot t_0\right) \cdot \left(t_0 \cdot -2\right)
\end{array}
\end{array}
Initial program 38.9%
diff-cos48.8%
div-inv48.8%
metadata-eval48.8%
div-inv48.8%
+-commutative48.8%
metadata-eval48.8%
Applied egg-rr48.8%
*-commutative48.8%
+-commutative48.8%
associate--l+80.3%
+-inverses80.3%
distribute-lft-in80.3%
metadata-eval80.3%
*-commutative80.3%
associate-+r+80.4%
+-commutative80.4%
Simplified80.4%
Taylor expanded in x around -inf 80.4%
cancel-sign-sub-inv80.4%
metadata-eval80.4%
count-280.4%
distribute-lft-in80.4%
sin-sum99.4%
Applied egg-rr99.4%
fma-def99.4%
distribute-rgt-in99.4%
distribute-lft-out99.4%
metadata-eval99.4%
distribute-rgt-in99.4%
distribute-lft-out99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in eps around inf 99.4%
*-commutative99.4%
*-commutative99.4%
*-commutative99.4%
fma-def99.4%
associate-*l*99.4%
fma-def99.4%
+-commutative99.4%
*-commutative99.4%
*-commutative99.4%
fma-def99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (+ (* (cos x) t_0) (* (sin x) (cos (* 0.5 eps))))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * ((cos(x) * t_0) + (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 * ((cos(x) * t_0) + (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 * ((Math.cos(x) * t_0) + (Math.sin(x) * Math.cos((0.5 * eps)))));
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) return -2.0 * (t_0 * ((math.cos(x) * t_0) + (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(cos(x) * t_0) + 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 * ((cos(x) * t_0) + (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[(N[Cos[x], $MachinePrecision] * t$95$0), $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(\cos x \cdot t_0 + \sin x \cdot \cos \left(0.5 \cdot \varepsilon\right)\right)\right)
\end{array}
\end{array}
Initial program 38.9%
diff-cos48.8%
div-inv48.8%
metadata-eval48.8%
div-inv48.8%
+-commutative48.8%
metadata-eval48.8%
Applied egg-rr48.8%
*-commutative48.8%
+-commutative48.8%
associate--l+80.3%
+-inverses80.3%
distribute-lft-in80.3%
metadata-eval80.3%
*-commutative80.3%
associate-+r+80.4%
+-commutative80.4%
Simplified80.4%
Taylor expanded in x around -inf 80.4%
cancel-sign-sub-inv80.4%
metadata-eval80.4%
count-280.4%
distribute-lft-in80.4%
sin-sum99.4%
Applied egg-rr99.4%
fma-def99.4%
distribute-rgt-in99.4%
distribute-lft-out99.4%
metadata-eval99.4%
distribute-rgt-in99.4%
distribute-lft-out99.4%
metadata-eval99.4%
Simplified99.4%
fma-udef99.4%
*-rgt-identity99.4%
*-rgt-identity99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -6.2e-5) (not (<= eps 3.6e-5))) (- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps)))) (- (* (* eps eps) (* (cos x) -0.5)) (* (sin x) eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -6.2e-5) || !(eps <= 3.6e-5)) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
} else {
tmp = ((eps * eps) * (cos(x) * -0.5)) - (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 <= (-6.2d-5)) .or. (.not. (eps <= 3.6d-5))) then
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)))
else
tmp = ((eps * eps) * (cos(x) * (-0.5d0))) - (sin(x) * eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -6.2e-5) || !(eps <= 3.6e-5)) {
tmp = (Math.cos(x) * Math.cos(eps)) - (Math.cos(x) + (Math.sin(x) * Math.sin(eps)));
} else {
tmp = ((eps * eps) * (Math.cos(x) * -0.5)) - (Math.sin(x) * eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -6.2e-5) or not (eps <= 3.6e-5): tmp = (math.cos(x) * math.cos(eps)) - (math.cos(x) + (math.sin(x) * math.sin(eps))) else: tmp = ((eps * eps) * (math.cos(x) * -0.5)) - (math.sin(x) * eps) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -6.2e-5) || !(eps <= 3.6e-5)) tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(x) * sin(eps)))); else tmp = Float64(Float64(Float64(eps * eps) * Float64(cos(x) * -0.5)) - Float64(sin(x) * eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -6.2e-5) || ~((eps <= 3.6e-5))) tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps))); else tmp = ((eps * eps) * (cos(x) * -0.5)) - (sin(x) * eps); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -6.2e-5], N[Not[LessEqual[eps, 3.6e-5]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(eps * eps), $MachinePrecision] * N[(N[Cos[x], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -6.2 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 3.6 \cdot 10^{-5}\right):\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\cos x \cdot -0.5\right) - \sin x \cdot \varepsilon\\
\end{array}
\end{array}
if eps < -6.20000000000000027e-5 or 3.60000000000000009e-5 < eps Initial program 58.7%
sub-neg58.7%
cos-sum98.4%
associate-+l-98.5%
*-un-lft-identity98.5%
fma-neg98.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 98.5%
if -6.20000000000000027e-5 < eps < 3.60000000000000009e-5Initial program 18.8%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
*-commutative99.8%
associate-*l*99.8%
unpow299.8%
Simplified99.8%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ x eps)) (cos x)) -2e-5) (* -2.0 (pow (sin (* 0.5 eps)) 2.0)) (- (* (* eps eps) (* (cos x) -0.5)) (* (sin x) eps))))
double code(double x, double eps) {
double tmp;
if ((cos((x + eps)) - cos(x)) <= -2e-5) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
} else {
tmp = ((eps * eps) * (cos(x) * -0.5)) - (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 ((cos((x + eps)) - cos(x)) <= (-2d-5)) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
else
tmp = ((eps * eps) * (cos(x) * (-0.5d0))) - (sin(x) * eps)
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((0.5 * eps)), 2.0);
} else {
tmp = ((eps * eps) * (Math.cos(x) * -0.5)) - (Math.sin(x) * eps);
}
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((0.5 * eps)), 2.0) else: tmp = ((eps * eps) * (math.cos(x) * -0.5)) - (math.sin(x) * eps) 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(0.5 * eps)) ^ 2.0)); else tmp = Float64(Float64(Float64(eps * eps) * Float64(cos(x) * -0.5)) - Float64(sin(x) * eps)); 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((0.5 * eps)) ^ 2.0); else tmp = ((eps * eps) * (cos(x) * -0.5)) - (sin(x) * eps); 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[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(eps * eps), $MachinePrecision] * N[(N[Cos[x], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * eps), $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(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\cos x \cdot -0.5\right) - \sin x \cdot \varepsilon\\
\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%
metadata-eval84.4%
div-inv84.4%
+-commutative84.4%
metadata-eval84.4%
Applied egg-rr84.4%
*-commutative84.4%
+-commutative84.4%
associate--l+84.0%
+-inverses84.0%
distribute-lft-in84.0%
metadata-eval84.0%
*-commutative84.0%
associate-+r+84.4%
+-commutative84.4%
Simplified84.4%
Taylor expanded in x around 0 84.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 (if (<= (- (cos (+ x eps)) (cos x)) -2e-16) (+ (cos eps) -1.0) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((cos((x + eps)) - cos(x)) <= -2e-16) {
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 ((cos((x + eps)) - cos(x)) <= (-2d-16)) 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 ((Math.cos((x + eps)) - Math.cos(x)) <= -2e-16) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = Math.sin(x) * -eps;
}
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 = math.sin(x) * -eps 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(sin(x) * Float64(-eps)); 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 = sin(x) * -eps; 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[(N[Sin[x], $MachinePrecision] * (-eps)), $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}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\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%
mul-1-neg62.3%
*-commutative62.3%
distribute-rgt-neg-in62.3%
Simplified62.3%
Final simplification69.5%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 eps)) (sin (* 0.5 (- eps (* x -2.0)))))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * eps)) * sin((0.5 * (eps - (x * -2.0)))));
}
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 * (-2.0d0))))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * eps)) * Math.sin((0.5 * (eps - (x * -2.0)))));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * eps)) * math.sin((0.5 * (eps - (x * -2.0)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * eps)) * sin((0.5 * (eps - (x * -2.0))))); 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 * -2.0), $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 - x \cdot -2\right)\right)\right)
\end{array}
Initial program 38.9%
diff-cos48.8%
div-inv48.8%
metadata-eval48.8%
div-inv48.8%
+-commutative48.8%
metadata-eval48.8%
Applied egg-rr48.8%
*-commutative48.8%
+-commutative48.8%
associate--l+80.3%
+-inverses80.3%
distribute-lft-in80.3%
metadata-eval80.3%
*-commutative80.3%
associate-+r+80.4%
+-commutative80.4%
Simplified80.4%
Taylor expanded in x around -inf 80.4%
Final simplification80.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* 0.5 eps))))
(if (or (<= x -3500.0) (not (<= x 5e-49)))
(* -2.0 (* (sin x) t_0))
(* -2.0 (pow t_0 2.0)))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
double tmp;
if ((x <= -3500.0) || !(x <= 5e-49)) {
tmp = -2.0 * (sin(x) * t_0);
} else {
tmp = -2.0 * pow(t_0, 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((0.5d0 * eps))
if ((x <= (-3500.0d0)) .or. (.not. (x <= 5d-49))) then
tmp = (-2.0d0) * (sin(x) * t_0)
else
tmp = (-2.0d0) * (t_0 ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
double tmp;
if ((x <= -3500.0) || !(x <= 5e-49)) {
tmp = -2.0 * (Math.sin(x) * t_0);
} else {
tmp = -2.0 * Math.pow(t_0, 2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) tmp = 0 if (x <= -3500.0) or not (x <= 5e-49): tmp = -2.0 * (math.sin(x) * t_0) else: tmp = -2.0 * math.pow(t_0, 2.0) return tmp
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) tmp = 0.0 if ((x <= -3500.0) || !(x <= 5e-49)) tmp = Float64(-2.0 * Float64(sin(x) * t_0)); else tmp = Float64(-2.0 * (t_0 ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((0.5 * eps)); tmp = 0.0; if ((x <= -3500.0) || ~((x <= 5e-49))) tmp = -2.0 * (sin(x) * t_0); else tmp = -2.0 * (t_0 ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -3500.0], N[Not[LessEqual[x, 5e-49]], $MachinePrecision]], N[(-2.0 * N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
\mathbf{if}\;x \leq -3500 \lor \neg \left(x \leq 5 \cdot 10^{-49}\right):\\
\;\;\;\;-2 \cdot \left(\sin x \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -3500 or 4.9999999999999999e-49 < x Initial program 9.1%
diff-cos9.4%
div-inv9.4%
metadata-eval9.4%
div-inv9.4%
+-commutative9.4%
metadata-eval9.4%
Applied egg-rr9.4%
*-commutative9.4%
+-commutative9.4%
associate--l+63.9%
+-inverses63.9%
distribute-lft-in63.9%
metadata-eval63.9%
*-commutative63.9%
associate-+r+64.1%
+-commutative64.1%
Simplified64.1%
Taylor expanded in x around -inf 64.1%
Taylor expanded in eps around 0 61.9%
if -3500 < x < 4.9999999999999999e-49Initial program 70.7%
diff-cos90.7%
div-inv90.7%
metadata-eval90.7%
div-inv90.7%
+-commutative90.7%
metadata-eval90.7%
Applied egg-rr90.7%
*-commutative90.7%
+-commutative90.7%
associate--l+97.8%
+-inverses97.8%
distribute-lft-in97.8%
metadata-eval97.8%
*-commutative97.8%
associate-+r+97.8%
+-commutative97.8%
Simplified97.8%
Taylor expanded in x around 0 89.2%
Final simplification75.1%
(FPCore (x eps) :precision binary64 (if (or (<= x -8200.0) (not (<= x 5.1e-49))) (* (sin x) (- eps)) (* -2.0 (pow (sin (* 0.5 eps)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -8200.0) || !(x <= 5.1e-49)) {
tmp = sin(x) * -eps;
} else {
tmp = -2.0 * pow(sin((0.5 * 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 ((x <= (-8200.0d0)) .or. (.not. (x <= 5.1d-49))) then
tmp = sin(x) * -eps
else
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -8200.0) || !(x <= 5.1e-49)) {
tmp = Math.sin(x) * -eps;
} else {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -8200.0) or not (x <= 5.1e-49): tmp = math.sin(x) * -eps else: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -8200.0) || !(x <= 5.1e-49)) tmp = Float64(sin(x) * Float64(-eps)); else tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -8200.0) || ~((x <= 5.1e-49))) tmp = sin(x) * -eps; else tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -8200.0], N[Not[LessEqual[x, 5.1e-49]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8200 \lor \neg \left(x \leq 5.1 \cdot 10^{-49}\right):\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\end{array}
\end{array}
if x < -8200 or 5.10000000000000026e-49 < x Initial program 9.2%
Taylor expanded in eps around 0 58.4%
mul-1-neg58.4%
*-commutative58.4%
distribute-rgt-neg-in58.4%
Simplified58.4%
if -8200 < x < 5.10000000000000026e-49Initial program 70.1%
diff-cos90.1%
div-inv90.1%
metadata-eval90.1%
div-inv90.1%
+-commutative90.1%
metadata-eval90.1%
Applied egg-rr90.1%
*-commutative90.1%
+-commutative90.1%
associate--l+97.1%
+-inverses97.1%
distribute-lft-in97.1%
metadata-eval97.1%
*-commutative97.1%
associate-+r+97.1%
+-commutative97.1%
Simplified97.1%
Taylor expanded in x around 0 88.6%
Final simplification73.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000175) (not (<= eps 0.00017))) (+ (cos eps) -1.0) (* eps (* eps -0.5))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000175) || !(eps <= 0.00017)) {
tmp = cos(eps) + -1.0;
} else {
tmp = eps * (eps * -0.5);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.000175d0)) .or. (.not. (eps <= 0.00017d0))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = eps * (eps * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.000175) || !(eps <= 0.00017)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * (eps * -0.5);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000175) or not (eps <= 0.00017): tmp = math.cos(eps) + -1.0 else: tmp = eps * (eps * -0.5) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000175) || !(eps <= 0.00017)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(eps * Float64(eps * -0.5)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000175) || ~((eps <= 0.00017))) tmp = cos(eps) + -1.0; else tmp = eps * (eps * -0.5); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000175], N[Not[LessEqual[eps, 0.00017]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000175 \lor \neg \left(\varepsilon \leq 0.00017\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\end{array}
\end{array}
if eps < -1.74999999999999998e-4 or 1.7e-4 < eps Initial program 58.7%
Taylor expanded in x around 0 60.7%
if -1.74999999999999998e-4 < eps < 1.7e-4Initial program 18.8%
Taylor expanded in x around 0 18.8%
Taylor expanded in eps around 0 36.6%
*-commutative36.6%
unpow236.6%
Simplified36.6%
Taylor expanded in eps around 0 36.6%
*-commutative36.6%
unpow236.6%
associate-*r*36.7%
Simplified36.7%
Final simplification48.8%
(FPCore (x eps) :precision binary64 (* eps (* eps -0.5)))
double code(double x, double eps) {
return eps * (eps * -0.5);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * (eps * (-0.5d0))
end function
public static double code(double x, double eps) {
return eps * (eps * -0.5);
}
def code(x, eps): return eps * (eps * -0.5)
function code(x, eps) return Float64(eps * Float64(eps * -0.5)) end
function tmp = code(x, eps) tmp = eps * (eps * -0.5); end
code[x_, eps_] := N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)
\end{array}
Initial program 38.9%
Taylor expanded in x around 0 39.9%
Taylor expanded in eps around 0 20.0%
*-commutative20.0%
unpow220.0%
Simplified20.0%
Taylor expanded in eps around 0 20.0%
*-commutative20.0%
unpow220.0%
associate-*r*20.0%
Simplified20.0%
Final simplification20.0%
herbie shell --seed 2023297
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))