
(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 (* (cos eps) (cos x))))
(if (<= eps -3.9e-5)
(- t_0 (fma (sin eps) (sin x) (cos x)))
(if (<= eps 2.6e-5)
(- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))
(- (- t_0 (* (sin eps) (sin x))) (cos x))))))
double code(double x, double eps) {
double t_0 = cos(eps) * cos(x);
double tmp;
if (eps <= -3.9e-5) {
tmp = t_0 - fma(sin(eps), sin(x), cos(x));
} else if (eps <= 2.6e-5) {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (eps * sin(x));
} else {
tmp = (t_0 - (sin(eps) * sin(x))) - cos(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64(cos(eps) * cos(x)) tmp = 0.0 if (eps <= -3.9e-5) tmp = Float64(t_0 - fma(sin(eps), sin(x), cos(x))); elseif (eps <= 2.6e-5) tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(eps * sin(x))); else tmp = Float64(Float64(t_0 - Float64(sin(eps) * sin(x))) - cos(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -3.9e-5], N[(t$95$0 - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision] + N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.6e-5], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon \cdot \cos x\\
\mathbf{if}\;\varepsilon \leq -3.9 \cdot 10^{-5}:\\
\;\;\;\;t_0 - \mathsf{fma}\left(\sin \varepsilon, \sin x, \cos x\right)\\
\mathbf{elif}\;\varepsilon \leq 2.6 \cdot 10^{-5}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(t_0 - \sin \varepsilon \cdot \sin x\right) - \cos x\\
\end{array}
\end{array}
if eps < -3.8999999999999999e-5Initial program 59.8%
sub-neg59.8%
cos-sum98.8%
associate-+l-98.8%
fma-neg98.8%
Applied egg-rr98.8%
fma-neg98.8%
*-commutative98.8%
*-commutative98.8%
fma-neg98.8%
remove-double-neg98.8%
Simplified98.8%
if -3.8999999999999999e-5 < eps < 2.59999999999999984e-5Initial program 23.9%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
if 2.59999999999999984e-5 < eps Initial program 49.2%
cos-sum98.5%
Applied egg-rr98.5%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -2.7e-5) (not (<= eps 3.5e-5))) (- (- (* (cos eps) (cos x)) (* (sin eps) (sin x))) (cos x)) (- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -2.7e-5) || !(eps <= 3.5e-5)) {
tmp = ((cos(eps) * cos(x)) - (sin(eps) * sin(x))) - cos(x);
} else {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (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 <= (-2.7d-5)) .or. (.not. (eps <= 3.5d-5))) then
tmp = ((cos(eps) * cos(x)) - (sin(eps) * sin(x))) - cos(x)
else
tmp = (cos(x) * ((-0.5d0) * (eps ** 2.0d0))) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -2.7e-5) || !(eps <= 3.5e-5)) {
tmp = ((Math.cos(eps) * Math.cos(x)) - (Math.sin(eps) * Math.sin(x))) - Math.cos(x);
} else {
tmp = (Math.cos(x) * (-0.5 * Math.pow(eps, 2.0))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -2.7e-5) or not (eps <= 3.5e-5): tmp = ((math.cos(eps) * math.cos(x)) - (math.sin(eps) * math.sin(x))) - math.cos(x) else: tmp = (math.cos(x) * (-0.5 * math.pow(eps, 2.0))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -2.7e-5) || !(eps <= 3.5e-5)) tmp = Float64(Float64(Float64(cos(eps) * cos(x)) - Float64(sin(eps) * sin(x))) - cos(x)); else tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -2.7e-5) || ~((eps <= 3.5e-5))) tmp = ((cos(eps) * cos(x)) - (sin(eps) * sin(x))) - cos(x); else tmp = (cos(x) * (-0.5 * (eps ^ 2.0))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -2.7e-5], N[Not[LessEqual[eps, 3.5e-5]], $MachinePrecision]], N[(N[(N[(N[Cos[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.7 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 3.5 \cdot 10^{-5}\right):\\
\;\;\;\;\left(\cos \varepsilon \cdot \cos x - \sin \varepsilon \cdot \sin x\right) - \cos x\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -2.6999999999999999e-5 or 3.4999999999999997e-5 < eps Initial program 55.1%
cos-sum98.6%
Applied egg-rr98.6%
if -2.6999999999999999e-5 < eps < 3.4999999999999997e-5Initial program 23.9%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5)))))
double code(double x, double eps) {
return sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
}
function code(x, eps) return Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))) end
code[x_, eps_] := N[(N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 40.5%
diff-cos46.0%
div-inv46.0%
associate--l+46.0%
metadata-eval46.0%
div-inv46.0%
+-commutative46.0%
associate-+l+46.0%
metadata-eval46.0%
Applied egg-rr46.0%
associate-*r*46.0%
*-commutative46.0%
*-commutative46.0%
+-commutative46.0%
count-246.0%
fma-def46.0%
sub-neg46.0%
mul-1-neg46.0%
+-commutative46.0%
associate-+r+76.4%
mul-1-neg76.4%
sub-neg76.4%
+-inverses76.4%
remove-double-neg76.4%
mul-1-neg76.4%
sub-neg76.4%
neg-sub076.4%
mul-1-neg76.4%
remove-double-neg76.4%
Simplified76.4%
Final simplification76.4%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* eps 0.5))) (t_1 (* -2.0 t_0))) (if (or (<= x -2.7e-10) (not (<= x 7.5e-13))) (* (sin x) t_1) (* t_1 t_0))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double t_1 = -2.0 * t_0;
double tmp;
if ((x <= -2.7e-10) || !(x <= 7.5e-13)) {
tmp = sin(x) * t_1;
} else {
tmp = t_1 * 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 = sin((eps * 0.5d0))
t_1 = (-2.0d0) * t_0
if ((x <= (-2.7d-10)) .or. (.not. (x <= 7.5d-13))) then
tmp = sin(x) * t_1
else
tmp = t_1 * t_0
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 = -2.0 * t_0;
double tmp;
if ((x <= -2.7e-10) || !(x <= 7.5e-13)) {
tmp = Math.sin(x) * t_1;
} else {
tmp = t_1 * t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) t_1 = -2.0 * t_0 tmp = 0 if (x <= -2.7e-10) or not (x <= 7.5e-13): tmp = math.sin(x) * t_1 else: tmp = t_1 * t_0 return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) t_1 = Float64(-2.0 * t_0) tmp = 0.0 if ((x <= -2.7e-10) || !(x <= 7.5e-13)) tmp = Float64(sin(x) * t_1); else tmp = Float64(t_1 * t_0); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); t_1 = -2.0 * t_0; tmp = 0.0; if ((x <= -2.7e-10) || ~((x <= 7.5e-13))) tmp = sin(x) * t_1; else tmp = t_1 * t_0; 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[(-2.0 * t$95$0), $MachinePrecision]}, If[Or[LessEqual[x, -2.7e-10], N[Not[LessEqual[x, 7.5e-13]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * t$95$1), $MachinePrecision], N[(t$95$1 * t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
t_1 := -2 \cdot t_0\\
\mathbf{if}\;x \leq -2.7 \cdot 10^{-10} \lor \neg \left(x \leq 7.5 \cdot 10^{-13}\right):\\
\;\;\;\;\sin x \cdot t_1\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot t_0\\
\end{array}
\end{array}
if x < -2.7e-10 or 7.5000000000000004e-13 < x Initial program 6.9%
diff-cos6.3%
div-inv6.3%
associate--l+6.3%
metadata-eval6.3%
div-inv6.3%
+-commutative6.3%
associate-+l+6.3%
metadata-eval6.3%
Applied egg-rr6.3%
associate-*r*6.3%
*-commutative6.3%
*-commutative6.3%
+-commutative6.3%
count-26.3%
fma-def6.3%
sub-neg6.3%
mul-1-neg6.3%
+-commutative6.3%
associate-+r+57.0%
mul-1-neg57.0%
sub-neg57.0%
+-inverses57.0%
remove-double-neg57.0%
mul-1-neg57.0%
sub-neg57.0%
neg-sub057.0%
mul-1-neg57.0%
remove-double-neg57.0%
Simplified57.0%
Taylor expanded in eps around 0 56.4%
if -2.7e-10 < x < 7.5000000000000004e-13Initial program 80.4%
diff-cos93.1%
div-inv93.1%
associate--l+93.1%
metadata-eval93.1%
div-inv93.1%
+-commutative93.1%
associate-+l+93.1%
metadata-eval93.1%
Applied egg-rr93.1%
associate-*r*93.1%
*-commutative93.1%
*-commutative93.1%
+-commutative93.1%
count-293.1%
fma-def93.1%
sub-neg93.1%
mul-1-neg93.1%
+-commutative93.1%
associate-+r+99.4%
mul-1-neg99.4%
sub-neg99.4%
+-inverses99.4%
remove-double-neg99.4%
mul-1-neg99.4%
sub-neg99.4%
neg-sub099.4%
mul-1-neg99.4%
remove-double-neg99.4%
Simplified99.4%
Taylor expanded in x around 0 93.1%
Final simplification73.1%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* eps 0.5)) (sin (* 0.5 (- eps (* x -2.0)))))))
double code(double x, double eps) {
return -2.0 * (sin((eps * 0.5)) * 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((eps * 0.5d0)) * sin((0.5d0 * (eps - (x * (-2.0d0))))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((eps * 0.5)) * Math.sin((0.5 * (eps - (x * -2.0)))));
}
def code(x, eps): return -2.0 * (math.sin((eps * 0.5)) * math.sin((0.5 * (eps - (x * -2.0)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(eps * 0.5)) * sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps - (x * -2.0))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(eps * 0.5), $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(\varepsilon \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right)\right)
\end{array}
Initial program 40.5%
log1p-expm1-u40.4%
Applied egg-rr40.4%
diff-cos45.9%
log1p-expm1-u46.0%
div-inv46.0%
metadata-eval46.0%
div-inv46.0%
metadata-eval46.0%
Applied egg-rr46.0%
*-commutative46.0%
+-commutative46.0%
associate--l+76.3%
*-commutative76.3%
+-commutative76.3%
associate-+l+76.4%
Simplified76.4%
Taylor expanded in x around -inf 76.4%
Final simplification76.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -3.8e-9) (not (<= x 5.2e-18)))
(* (sin x) (* -2.0 t_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 <= -3.8e-9) || !(x <= 5.2e-18)) {
tmp = sin(x) * (-2.0 * 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((eps * 0.5d0))
if ((x <= (-3.8d-9)) .or. (.not. (x <= 5.2d-18))) then
tmp = sin(x) * ((-2.0d0) * 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((eps * 0.5));
double tmp;
if ((x <= -3.8e-9) || !(x <= 5.2e-18)) {
tmp = Math.sin(x) * (-2.0 * t_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 <= -3.8e-9) or not (x <= 5.2e-18): tmp = math.sin(x) * (-2.0 * t_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 <= -3.8e-9) || !(x <= 5.2e-18)) tmp = Float64(sin(x) * Float64(-2.0 * t_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 <= -3.8e-9) || ~((x <= 5.2e-18))) tmp = sin(x) * (-2.0 * 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[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -3.8e-9], N[Not[LessEqual[x, 5.2e-18]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * N[(-2.0 * 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(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -3.8 \cdot 10^{-9} \lor \neg \left(x \leq 5.2 \cdot 10^{-18}\right):\\
\;\;\;\;\sin x \cdot \left(-2 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -3.80000000000000011e-9 or 5.2000000000000001e-18 < x Initial program 6.9%
diff-cos6.3%
div-inv6.3%
associate--l+6.3%
metadata-eval6.3%
div-inv6.3%
+-commutative6.3%
associate-+l+6.3%
metadata-eval6.3%
Applied egg-rr6.3%
associate-*r*6.3%
*-commutative6.3%
*-commutative6.3%
+-commutative6.3%
count-26.3%
fma-def6.3%
sub-neg6.3%
mul-1-neg6.3%
+-commutative6.3%
associate-+r+57.0%
mul-1-neg57.0%
sub-neg57.0%
+-inverses57.0%
remove-double-neg57.0%
mul-1-neg57.0%
sub-neg57.0%
neg-sub057.0%
mul-1-neg57.0%
remove-double-neg57.0%
Simplified57.0%
Taylor expanded in eps around 0 56.4%
if -3.80000000000000011e-9 < x < 5.2000000000000001e-18Initial program 80.4%
diff-cos93.1%
div-inv93.1%
associate--l+93.1%
metadata-eval93.1%
div-inv93.1%
+-commutative93.1%
associate-+l+93.1%
metadata-eval93.1%
Applied egg-rr93.1%
associate-*r*93.1%
*-commutative93.1%
*-commutative93.1%
+-commutative93.1%
count-293.1%
fma-def93.1%
sub-neg93.1%
mul-1-neg93.1%
+-commutative93.1%
associate-+r+99.4%
mul-1-neg99.4%
sub-neg99.4%
+-inverses99.4%
remove-double-neg99.4%
mul-1-neg99.4%
sub-neg99.4%
neg-sub099.4%
mul-1-neg99.4%
remove-double-neg99.4%
Simplified99.4%
Taylor expanded in x around 0 93.1%
Final simplification73.1%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.85e-5) (not (<= eps 3.9e-5))) (- (cos eps) (cos x)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.85e-5) || !(eps <= 3.9e-5)) {
tmp = cos(eps) - cos(x);
} else {
tmp = sin(x) * -eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.85d-5)) .or. (.not. (eps <= 3.9d-5))) then
tmp = cos(eps) - cos(x)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.85e-5) || !(eps <= 3.9e-5)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.85e-5) or not (eps <= 3.9e-5): tmp = math.cos(eps) - math.cos(x) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.85e-5) || !(eps <= 3.9e-5)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.85e-5) || ~((eps <= 3.9e-5))) tmp = cos(eps) - cos(x); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.85e-5], N[Not[LessEqual[eps, 3.9e-5]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.85 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 3.9 \cdot 10^{-5}\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.84999999999999991e-5 or 3.8999999999999999e-5 < eps Initial program 55.1%
Taylor expanded in x around 0 58.4%
if -1.84999999999999991e-5 < eps < 3.8999999999999999e-5Initial program 23.9%
Taylor expanded in eps around 0 86.8%
mul-1-neg86.8%
*-commutative86.8%
distribute-rgt-neg-in86.8%
Simplified86.8%
Final simplification71.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)) (t_1 (* -0.5 (pow eps 2.0))))
(if (<= eps -1.7e-9)
t_0
(if (<= eps -1.6e-157)
t_1
(if (<= eps 1.5e-118) (* eps (- x)) (if (<= eps 1.11e-13) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double t_1 = -0.5 * pow(eps, 2.0);
double tmp;
if (eps <= -1.7e-9) {
tmp = t_0;
} else if (eps <= -1.6e-157) {
tmp = t_1;
} else if (eps <= 1.5e-118) {
tmp = eps * -x;
} else if (eps <= 1.11e-13) {
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 = (-0.5d0) * (eps ** 2.0d0)
if (eps <= (-1.7d-9)) then
tmp = t_0
else if (eps <= (-1.6d-157)) then
tmp = t_1
else if (eps <= 1.5d-118) then
tmp = eps * -x
else if (eps <= 1.11d-13) 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 = -0.5 * Math.pow(eps, 2.0);
double tmp;
if (eps <= -1.7e-9) {
tmp = t_0;
} else if (eps <= -1.6e-157) {
tmp = t_1;
} else if (eps <= 1.5e-118) {
tmp = eps * -x;
} else if (eps <= 1.11e-13) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 t_1 = -0.5 * math.pow(eps, 2.0) tmp = 0 if eps <= -1.7e-9: tmp = t_0 elif eps <= -1.6e-157: tmp = t_1 elif eps <= 1.5e-118: tmp = eps * -x elif eps <= 1.11e-13: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) t_1 = Float64(-0.5 * (eps ^ 2.0)) tmp = 0.0 if (eps <= -1.7e-9) tmp = t_0; elseif (eps <= -1.6e-157) tmp = t_1; elseif (eps <= 1.5e-118) tmp = Float64(eps * Float64(-x)); elseif (eps <= 1.11e-13) 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 = -0.5 * (eps ^ 2.0); tmp = 0.0; if (eps <= -1.7e-9) tmp = t_0; elseif (eps <= -1.6e-157) tmp = t_1; elseif (eps <= 1.5e-118) tmp = eps * -x; elseif (eps <= 1.11e-13) 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[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -1.7e-9], t$95$0, If[LessEqual[eps, -1.6e-157], t$95$1, If[LessEqual[eps, 1.5e-118], N[(eps * (-x)), $MachinePrecision], If[LessEqual[eps, 1.11e-13], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
t_1 := -0.5 \cdot {\varepsilon}^{2}\\
\mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-9}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -1.6 \cdot 10^{-157}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 1.5 \cdot 10^{-118}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{elif}\;\varepsilon \leq 1.11 \cdot 10^{-13}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.6999999999999999e-9 or 1.10999999999999994e-13 < eps Initial program 54.0%
Taylor expanded in x around 0 55.4%
if -1.6999999999999999e-9 < eps < -1.6000000000000001e-157 or 1.50000000000000009e-118 < eps < 1.10999999999999994e-13Initial program 5.4%
Taylor expanded in x around 0 5.4%
Taylor expanded in eps around 0 36.2%
if -1.6000000000000001e-157 < eps < 1.50000000000000009e-118Initial program 35.5%
Taylor expanded in x around 0 33.8%
Taylor expanded in eps around 0 47.0%
associate-*r*47.0%
mul-1-neg47.0%
Simplified47.0%
Final simplification49.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.95e-7) (not (<= eps 7.3e-6))) (+ (cos eps) -1.0) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.95e-7) || !(eps <= 7.3e-6)) {
tmp = cos(eps) + -1.0;
} else {
tmp = sin(x) * -eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.95d-7)) .or. (.not. (eps <= 7.3d-6))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.95e-7) || !(eps <= 7.3e-6)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.95e-7) or not (eps <= 7.3e-6): tmp = math.cos(eps) + -1.0 else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.95e-7) || !(eps <= 7.3e-6)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.95e-7) || ~((eps <= 7.3e-6))) tmp = cos(eps) + -1.0; else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.95e-7], N[Not[LessEqual[eps, 7.3e-6]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.95 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 7.3 \cdot 10^{-6}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.95000000000000012e-7 or 7.30000000000000041e-6 < eps Initial program 55.1%
Taylor expanded in x around 0 56.6%
if -1.95000000000000012e-7 < eps < 7.30000000000000041e-6Initial program 23.9%
Taylor expanded in eps around 0 86.8%
mul-1-neg86.8%
*-commutative86.8%
distribute-rgt-neg-in86.8%
Simplified86.8%
Final simplification70.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.06e-35) (not (<= eps 190.0))) (+ (cos eps) -1.0) (* eps (- x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.06e-35) || !(eps <= 190.0)) {
tmp = cos(eps) + -1.0;
} else {
tmp = 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 <= (-1.06d-35)) .or. (.not. (eps <= 190.0d0))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = eps * -x
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.06e-35) || !(eps <= 190.0)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * -x;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.06e-35) or not (eps <= 190.0): tmp = math.cos(eps) + -1.0 else: tmp = eps * -x return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.06e-35) || !(eps <= 190.0)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(eps * Float64(-x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.06e-35) || ~((eps <= 190.0))) tmp = cos(eps) + -1.0; else tmp = eps * -x; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.06e-35], N[Not[LessEqual[eps, 190.0]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(eps * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.06 \cdot 10^{-35} \lor \neg \left(\varepsilon \leq 190\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\end{array}
\end{array}
if eps < -1.06e-35 or 190 < eps Initial program 51.5%
Taylor expanded in x around 0 52.9%
if -1.06e-35 < eps < 190Initial program 25.9%
Taylor expanded in x around 0 24.3%
Taylor expanded in eps around 0 33.6%
associate-*r*33.6%
mul-1-neg33.6%
Simplified33.6%
Final simplification44.6%
(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 40.5%
Taylor expanded in x around 0 39.1%
Taylor expanded in eps around 0 16.2%
associate-*r*16.2%
mul-1-neg16.2%
Simplified16.2%
Final simplification16.2%
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
return 0.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
public static double code(double x, double eps) {
return 0.0;
}
def code(x, eps): return 0.0
function code(x, eps) return 0.0 end
function tmp = code(x, eps) tmp = 0.0; end
code[x_, eps_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 40.5%
Taylor expanded in x around 0 41.2%
Taylor expanded in eps around 0 12.9%
Final simplification12.9%
herbie shell --seed 2024011
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))