
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (fma (sin x) (cos (* 0.5 eps)) (* t_0 (cos x)))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * fma(sin(x), cos((0.5 * eps)), (t_0 * cos(x))));
}
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * fma(sin(x), cos(Float64(0.5 * eps)), Float64(t_0 * cos(x))))) 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[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] + N[(t$95$0 * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
-2 \cdot \left(t_0 \cdot \mathsf{fma}\left(\sin x, \cos \left(0.5 \cdot \varepsilon\right), t_0 \cdot \cos x\right)\right)
\end{array}
\end{array}
Initial program 41.7%
diff-cos50.7%
div-inv50.7%
metadata-eval50.7%
div-inv50.7%
+-commutative50.7%
metadata-eval50.7%
Applied egg-rr50.7%
*-commutative50.7%
+-commutative50.7%
associate--l+78.5%
+-inverses78.5%
distribute-lft-in78.5%
metadata-eval78.5%
*-commutative78.5%
associate-+r+78.5%
+-commutative78.5%
Simplified78.5%
Taylor expanded in eps around 0 78.6%
sin-sum99.4%
fma-def99.5%
*-commutative99.5%
Applied egg-rr99.5%
Taylor expanded in eps around inf 99.4%
+-commutative99.4%
*-commutative99.4%
*-commutative99.4%
fma-udef99.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 41.7%
diff-cos50.7%
div-inv50.7%
metadata-eval50.7%
div-inv50.7%
+-commutative50.7%
metadata-eval50.7%
Applied egg-rr50.7%
*-commutative50.7%
+-commutative50.7%
associate--l+78.5%
+-inverses78.5%
distribute-lft-in78.5%
metadata-eval78.5%
*-commutative78.5%
associate-+r+78.5%
+-commutative78.5%
Simplified78.5%
Taylor expanded in eps around 0 78.6%
sin-sum99.4%
fma-def99.5%
*-commutative99.5%
Applied egg-rr99.5%
Taylor expanded in eps around inf 99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -8.5e-5) (not (<= eps 5e-5))) (- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps)))) (- (* (* eps eps) (* (cos x) -0.5)) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -8.5e-5) || !(eps <= 5e-5)) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
} 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 ((eps <= (-8.5d-5)) .or. (.not. (eps <= 5d-5))) then
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)))
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 ((eps <= -8.5e-5) || !(eps <= 5e-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)) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -8.5e-5) or not (eps <= 5e-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)) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -8.5e-5) || !(eps <= 5e-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(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -8.5e-5) || ~((eps <= 5e-5))) tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps))); else tmp = ((eps * eps) * (cos(x) * -0.5)) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -8.5e-5], N[Not[LessEqual[eps, 5e-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[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -8.5 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 5 \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) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -8.500000000000001e-5 or 5.00000000000000024e-5 < eps Initial program 57.0%
sub-neg57.0%
cos-sum98.9%
associate-+l-98.8%
fma-neg98.8%
Applied egg-rr98.8%
Taylor expanded in x around inf 98.8%
if -8.500000000000001e-5 < eps < 5.00000000000000024e-5Initial program 25.0%
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.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (cos x) (cos eps))) (t_1 (* (sin x) (sin eps))))
(if (<= eps -2.7e-5)
(- t_0 (+ (cos x) t_1))
(if (<= eps 2.1e-5)
(- (* (* eps eps) (* (cos x) -0.5)) (* eps (sin x)))
(- (- t_0 t_1) (cos x))))))
double code(double x, double eps) {
double t_0 = cos(x) * cos(eps);
double t_1 = sin(x) * sin(eps);
double tmp;
if (eps <= -2.7e-5) {
tmp = t_0 - (cos(x) + t_1);
} else if (eps <= 2.1e-5) {
tmp = ((eps * eps) * (cos(x) * -0.5)) - (eps * sin(x));
} else {
tmp = (t_0 - t_1) - cos(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos(x) * cos(eps)
t_1 = sin(x) * sin(eps)
if (eps <= (-2.7d-5)) then
tmp = t_0 - (cos(x) + t_1)
else if (eps <= 2.1d-5) then
tmp = ((eps * eps) * (cos(x) * (-0.5d0))) - (eps * sin(x))
else
tmp = (t_0 - t_1) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(x) * Math.cos(eps);
double t_1 = Math.sin(x) * Math.sin(eps);
double tmp;
if (eps <= -2.7e-5) {
tmp = t_0 - (Math.cos(x) + t_1);
} else if (eps <= 2.1e-5) {
tmp = ((eps * eps) * (Math.cos(x) * -0.5)) - (eps * Math.sin(x));
} else {
tmp = (t_0 - t_1) - Math.cos(x);
}
return tmp;
}
def code(x, eps): t_0 = math.cos(x) * math.cos(eps) t_1 = math.sin(x) * math.sin(eps) tmp = 0 if eps <= -2.7e-5: tmp = t_0 - (math.cos(x) + t_1) elif eps <= 2.1e-5: tmp = ((eps * eps) * (math.cos(x) * -0.5)) - (eps * math.sin(x)) else: tmp = (t_0 - t_1) - math.cos(x) return tmp
function code(x, eps) t_0 = Float64(cos(x) * cos(eps)) t_1 = Float64(sin(x) * sin(eps)) tmp = 0.0 if (eps <= -2.7e-5) tmp = Float64(t_0 - Float64(cos(x) + t_1)); elseif (eps <= 2.1e-5) tmp = Float64(Float64(Float64(eps * eps) * Float64(cos(x) * -0.5)) - Float64(eps * sin(x))); else tmp = Float64(Float64(t_0 - t_1) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(x) * cos(eps); t_1 = sin(x) * sin(eps); tmp = 0.0; if (eps <= -2.7e-5) tmp = t_0 - (cos(x) + t_1); elseif (eps <= 2.1e-5) tmp = ((eps * eps) * (cos(x) * -0.5)) - (eps * sin(x)); else tmp = (t_0 - t_1) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -2.7e-5], N[(t$95$0 - N[(N[Cos[x], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.1e-5], 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[(t$95$0 - t$95$1), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \cos \varepsilon\\
t_1 := \sin x \cdot \sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -2.7 \cdot 10^{-5}:\\
\;\;\;\;t_0 - \left(\cos x + t_1\right)\\
\mathbf{elif}\;\varepsilon \leq 2.1 \cdot 10^{-5}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\cos x \cdot -0.5\right) - \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(t_0 - t_1\right) - \cos x\\
\end{array}
\end{array}
if eps < -2.6999999999999999e-5Initial program 55.2%
sub-neg55.2%
cos-sum99.1%
associate-+l-99.2%
fma-neg99.2%
Applied egg-rr99.2%
Taylor expanded in x around inf 99.2%
if -2.6999999999999999e-5 < eps < 2.09999999999999988e-5Initial program 25.0%
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%
if 2.09999999999999988e-5 < eps Initial program 58.4%
cos-sum98.6%
Applied egg-rr98.6%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 eps)) (sin (+ (* 0.5 eps) x)))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * eps)) * sin(((0.5 * eps) + 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)))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * eps)) * Math.sin(((0.5 * eps) + x)));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * eps)) * math.sin(((0.5 * eps) + x)))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(Float64(Float64(0.5 * eps) + x)))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * eps)) * sin(((0.5 * eps) + x))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(N[(0.5 * eps), $MachinePrecision] + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \varepsilon + x\right)\right)
\end{array}
Initial program 41.7%
diff-cos50.7%
div-inv50.7%
metadata-eval50.7%
div-inv50.7%
+-commutative50.7%
metadata-eval50.7%
Applied egg-rr50.7%
*-commutative50.7%
+-commutative50.7%
associate--l+78.5%
+-inverses78.5%
distribute-lft-in78.5%
metadata-eval78.5%
*-commutative78.5%
associate-+r+78.5%
+-commutative78.5%
Simplified78.5%
Taylor expanded in eps around 0 78.6%
Taylor expanded in eps around inf 78.6%
Final simplification78.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0025) (not (<= eps 0.12))) (- (cos eps) (cos x)) (* -2.0 (* (* 0.5 eps) (sin (+ (* 0.5 eps) x))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0025) || !(eps <= 0.12)) {
tmp = cos(eps) - cos(x);
} else {
tmp = -2.0 * ((0.5 * eps) * sin(((0.5 * eps) + 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.0025d0)) .or. (.not. (eps <= 0.12d0))) then
tmp = cos(eps) - cos(x)
else
tmp = (-2.0d0) * ((0.5d0 * eps) * sin(((0.5d0 * eps) + x)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0025) || !(eps <= 0.12)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = -2.0 * ((0.5 * eps) * Math.sin(((0.5 * eps) + x)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0025) or not (eps <= 0.12): tmp = math.cos(eps) - math.cos(x) else: tmp = -2.0 * ((0.5 * eps) * math.sin(((0.5 * eps) + x))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0025) || !(eps <= 0.12)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(-2.0 * Float64(Float64(0.5 * eps) * sin(Float64(Float64(0.5 * eps) + x)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0025) || ~((eps <= 0.12))) tmp = cos(eps) - cos(x); else tmp = -2.0 * ((0.5 * eps) * sin(((0.5 * eps) + x))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0025], N[Not[LessEqual[eps, 0.12]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(0.5 * eps), $MachinePrecision] * N[Sin[N[(N[(0.5 * eps), $MachinePrecision] + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0025 \lor \neg \left(\varepsilon \leq 0.12\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \varepsilon + x\right)\right)\\
\end{array}
\end{array}
if eps < -0.00250000000000000005 or 0.12 < eps Initial program 57.8%
Taylor expanded in x around 0 60.0%
if -0.00250000000000000005 < eps < 0.12Initial program 24.6%
diff-cos42.9%
div-inv42.9%
metadata-eval42.9%
div-inv42.9%
+-commutative42.9%
metadata-eval42.9%
Applied egg-rr42.9%
*-commutative42.9%
+-commutative42.9%
associate--l+98.4%
+-inverses98.4%
distribute-lft-in98.4%
metadata-eval98.4%
*-commutative98.4%
associate-+r+98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in eps around 0 98.4%
Taylor expanded in eps around 0 98.4%
Final simplification78.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.007) (not (<= eps 0.038))) (+ (cos eps) -1.0) (* -2.0 (* (* 0.5 eps) (sin (+ (* 0.5 eps) x))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.007) || !(eps <= 0.038)) {
tmp = cos(eps) + -1.0;
} else {
tmp = -2.0 * ((0.5 * eps) * sin(((0.5 * eps) + 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.007d0)) .or. (.not. (eps <= 0.038d0))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = (-2.0d0) * ((0.5d0 * eps) * sin(((0.5d0 * eps) + x)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.007) || !(eps <= 0.038)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = -2.0 * ((0.5 * eps) * Math.sin(((0.5 * eps) + x)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.007) or not (eps <= 0.038): tmp = math.cos(eps) + -1.0 else: tmp = -2.0 * ((0.5 * eps) * math.sin(((0.5 * eps) + x))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.007) || !(eps <= 0.038)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(-2.0 * Float64(Float64(0.5 * eps) * sin(Float64(Float64(0.5 * eps) + x)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.007) || ~((eps <= 0.038))) tmp = cos(eps) + -1.0; else tmp = -2.0 * ((0.5 * eps) * sin(((0.5 * eps) + x))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.007], N[Not[LessEqual[eps, 0.038]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(-2.0 * N[(N[(0.5 * eps), $MachinePrecision] * N[Sin[N[(N[(0.5 * eps), $MachinePrecision] + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.007 \lor \neg \left(\varepsilon \leq 0.038\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \varepsilon + x\right)\right)\\
\end{array}
\end{array}
if eps < -0.00700000000000000015 or 0.0379999999999999991 < eps Initial program 57.8%
Taylor expanded in x around 0 59.4%
if -0.00700000000000000015 < eps < 0.0379999999999999991Initial program 24.6%
diff-cos42.9%
div-inv42.9%
metadata-eval42.9%
div-inv42.9%
+-commutative42.9%
metadata-eval42.9%
Applied egg-rr42.9%
*-commutative42.9%
+-commutative42.9%
associate--l+98.4%
+-inverses98.4%
distribute-lft-in98.4%
metadata-eval98.4%
*-commutative98.4%
associate-+r+98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in eps around 0 98.4%
Taylor expanded in eps around 0 98.4%
Final simplification78.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)) (t_1 (* (* eps eps) -0.5)))
(if (<= eps -0.00018)
t_0
(if (<= eps -2.2e-132)
t_1
(if (<= eps 4.2e-140) (* eps (- x)) (if (<= eps 0.038) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double t_1 = (eps * eps) * -0.5;
double tmp;
if (eps <= -0.00018) {
tmp = t_0;
} else if (eps <= -2.2e-132) {
tmp = t_1;
} else if (eps <= 4.2e-140) {
tmp = eps * -x;
} else if (eps <= 0.038) {
tmp = t_1;
} else {
tmp = t_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) :: t_1
real(8) :: tmp
t_0 = cos(eps) + (-1.0d0)
t_1 = (eps * eps) * (-0.5d0)
if (eps <= (-0.00018d0)) then
tmp = t_0
else if (eps <= (-2.2d-132)) then
tmp = t_1
else if (eps <= 4.2d-140) then
tmp = eps * -x
else if (eps <= 0.038d0) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(eps) + -1.0;
double t_1 = (eps * eps) * -0.5;
double tmp;
if (eps <= -0.00018) {
tmp = t_0;
} else if (eps <= -2.2e-132) {
tmp = t_1;
} else if (eps <= 4.2e-140) {
tmp = eps * -x;
} else if (eps <= 0.038) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 t_1 = (eps * eps) * -0.5 tmp = 0 if eps <= -0.00018: tmp = t_0 elif eps <= -2.2e-132: tmp = t_1 elif eps <= 4.2e-140: tmp = eps * -x elif eps <= 0.038: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) t_1 = Float64(Float64(eps * eps) * -0.5) tmp = 0.0 if (eps <= -0.00018) tmp = t_0; elseif (eps <= -2.2e-132) tmp = t_1; elseif (eps <= 4.2e-140) tmp = Float64(eps * Float64(-x)); elseif (eps <= 0.038) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) + -1.0; t_1 = (eps * eps) * -0.5; tmp = 0.0; if (eps <= -0.00018) tmp = t_0; elseif (eps <= -2.2e-132) tmp = t_1; elseif (eps <= 4.2e-140) tmp = eps * -x; elseif (eps <= 0.038) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[eps, -0.00018], t$95$0, If[LessEqual[eps, -2.2e-132], t$95$1, If[LessEqual[eps, 4.2e-140], N[(eps * (-x)), $MachinePrecision], If[LessEqual[eps, 0.038], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
t_1 := \left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\mathbf{if}\;\varepsilon \leq -0.00018:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -2.2 \cdot 10^{-132}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 4.2 \cdot 10^{-140}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{elif}\;\varepsilon \leq 0.038:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.80000000000000011e-4 or 0.0379999999999999991 < eps Initial program 57.8%
Taylor expanded in x around 0 59.4%
if -1.80000000000000011e-4 < eps < -2.19999999999999991e-132 or 4.20000000000000035e-140 < eps < 0.0379999999999999991Initial program 4.2%
Taylor expanded in x around 0 4.6%
Taylor expanded in eps around 0 44.9%
*-commutative44.9%
unpow244.9%
Simplified44.9%
if -2.19999999999999991e-132 < eps < 4.20000000000000035e-140Initial program 38.5%
Taylor expanded in eps around 0 97.5%
mul-1-neg97.5%
*-commutative97.5%
distribute-rgt-neg-in97.5%
Simplified97.5%
Taylor expanded in x around 0 58.9%
mul-1-neg58.9%
distribute-rgt-neg-in58.9%
Simplified58.9%
Final simplification56.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.6e-7) (not (<= eps 0.038))) (+ (cos eps) -1.0) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.6e-7) || !(eps <= 0.038)) {
tmp = cos(eps) + -1.0;
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.6d-7)) .or. (.not. (eps <= 0.038d0))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.6e-7) || !(eps <= 0.038)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.6e-7) or not (eps <= 0.038): tmp = math.cos(eps) + -1.0 else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.6e-7) || !(eps <= 0.038)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.6e-7) || ~((eps <= 0.038))) tmp = cos(eps) + -1.0; else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.6e-7], N[Not[LessEqual[eps, 0.038]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.6 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 0.038\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -1.6e-7 or 0.0379999999999999991 < eps Initial program 57.8%
Taylor expanded in x around 0 59.4%
if -1.6e-7 < eps < 0.0379999999999999991Initial program 24.6%
Taylor expanded in eps around 0 80.3%
mul-1-neg80.3%
*-commutative80.3%
distribute-rgt-neg-in80.3%
Simplified80.3%
Final simplification69.5%
(FPCore (x eps) :precision binary64 (if (or (<= x -2.5e-111) (not (<= x 1.55e-133))) (* eps (- x)) (* (* eps eps) -0.5)))
double code(double x, double eps) {
double tmp;
if ((x <= -2.5e-111) || !(x <= 1.55e-133)) {
tmp = eps * -x;
} 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 <= (-2.5d-111)) .or. (.not. (x <= 1.55d-133))) then
tmp = eps * -x
else
tmp = (eps * eps) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -2.5e-111) || !(x <= 1.55e-133)) {
tmp = eps * -x;
} else {
tmp = (eps * eps) * -0.5;
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -2.5e-111) or not (x <= 1.55e-133): tmp = eps * -x else: tmp = (eps * eps) * -0.5 return tmp
function code(x, eps) tmp = 0.0 if ((x <= -2.5e-111) || !(x <= 1.55e-133)) tmp = Float64(eps * Float64(-x)); else tmp = Float64(Float64(eps * eps) * -0.5); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -2.5e-111) || ~((x <= 1.55e-133))) tmp = eps * -x; else tmp = (eps * eps) * -0.5; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -2.5e-111], N[Not[LessEqual[x, 1.55e-133]], $MachinePrecision]], N[(eps * (-x)), $MachinePrecision], N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-111} \lor \neg \left(x \leq 1.55 \cdot 10^{-133}\right):\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\end{array}
\end{array}
if x < -2.5000000000000001e-111 or 1.55000000000000008e-133 < x Initial program 26.1%
Taylor expanded in eps around 0 47.1%
mul-1-neg47.1%
*-commutative47.1%
distribute-rgt-neg-in47.1%
Simplified47.1%
Taylor expanded in x around 0 17.5%
mul-1-neg17.5%
distribute-rgt-neg-in17.5%
Simplified17.5%
if -2.5000000000000001e-111 < x < 1.55000000000000008e-133Initial program 74.4%
Taylor expanded in x around 0 74.4%
Taylor expanded in eps around 0 52.9%
*-commutative52.9%
unpow252.9%
Simplified52.9%
Final simplification28.9%
(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 * Float64(-x)) end
function tmp = code(x, eps) tmp = eps * -x; end
code[x_, eps_] := N[(eps * (-x)), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(-x\right)
\end{array}
Initial program 41.7%
Taylor expanded in eps around 0 40.9%
mul-1-neg40.9%
*-commutative40.9%
distribute-rgt-neg-in40.9%
Simplified40.9%
Taylor expanded in x around 0 20.8%
mul-1-neg20.8%
distribute-rgt-neg-in20.8%
Simplified20.8%
Final simplification20.8%
herbie shell --seed 2023285
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))