
(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 13 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)))) (* (* t_0 (fma (cos x) t_0 (* (sin x) (cos (* 0.5 eps))))) -2.0)))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return (t_0 * fma(cos(x), t_0, (sin(x) * cos((0.5 * eps))))) * -2.0;
}
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(Float64(t_0 * fma(cos(x), t_0, Float64(sin(x) * cos(Float64(0.5 * eps))))) * -2.0) end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(N[(t$95$0 * N[(N[Cos[x], $MachinePrecision] * t$95$0 + N[(N[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
\left(t_0 \cdot \mathsf{fma}\left(\cos x, t_0, \sin x \cdot \cos \left(0.5 \cdot \varepsilon\right)\right)\right) \cdot -2
\end{array}
\end{array}
Initial program 37.0%
diff-cos47.1%
div-inv47.1%
metadata-eval47.1%
div-inv47.1%
+-commutative47.1%
metadata-eval47.1%
Applied egg-rr47.1%
*-commutative47.1%
+-commutative47.1%
associate--l+73.0%
*-commutative73.0%
associate-+r+73.2%
+-commutative73.2%
Simplified73.2%
distribute-lft-in73.2%
sin-sum99.4%
Applied egg-rr99.4%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.4%
*-commutative99.4%
*-commutative99.4%
fma-def99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (+ (* (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 * ((sin(x) * cos((0.5 * eps))) + (t_0 * cos(x))));
}
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 * ((sin(x) * cos((0.5d0 * eps))) + (t_0 * cos(x))))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
return -2.0 * (t_0 * ((Math.sin(x) * Math.cos((0.5 * eps))) + (t_0 * Math.cos(x))));
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) return -2.0 * (t_0 * ((math.sin(x) * math.cos((0.5 * eps))) + (t_0 * math.cos(x))))
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * Float64(Float64(sin(x) * cos(Float64(0.5 * eps))) + Float64(t_0 * cos(x))))) end
function tmp = code(x, eps) t_0 = sin((0.5 * eps)); tmp = -2.0 * (t_0 * ((sin(x) * cos((0.5 * eps))) + (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[(N[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $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 \left(\sin x \cdot \cos \left(0.5 \cdot \varepsilon\right) + t_0 \cdot \cos x\right)\right)
\end{array}
\end{array}
Initial program 37.0%
diff-cos47.1%
div-inv47.1%
metadata-eval47.1%
div-inv47.1%
+-commutative47.1%
metadata-eval47.1%
Applied egg-rr47.1%
*-commutative47.1%
+-commutative47.1%
associate--l+73.0%
*-commutative73.0%
associate-+r+73.2%
+-commutative73.2%
Simplified73.2%
distribute-lft-in73.2%
sin-sum99.4%
Applied egg-rr99.4%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.4%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00018) (not (<= eps 0.00015)))
(- (- (* (cos x) (cos eps)) (* (sin x) (sin eps))) (cos x))
(+
(* -0.5 (* eps (* eps (cos x))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00018) || !(eps <= 0.00015)) {
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x);
} else {
tmp = (-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - eps));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.00018d0)) .or. (.not. (eps <= 0.00015d0))) then
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x)
else
tmp = ((-0.5d0) * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666d0 * (eps ** 3.0d0)) - eps))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.00018) || !(eps <= 0.00015)) {
tmp = ((Math.cos(x) * Math.cos(eps)) - (Math.sin(x) * Math.sin(eps))) - Math.cos(x);
} else {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) + (Math.sin(x) * ((0.16666666666666666 * Math.pow(eps, 3.0)) - eps));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00018) or not (eps <= 0.00015): tmp = ((math.cos(x) * math.cos(eps)) - (math.sin(x) * math.sin(eps))) - math.cos(x) else: tmp = (-0.5 * (eps * (eps * math.cos(x)))) + (math.sin(x) * ((0.16666666666666666 * math.pow(eps, 3.0)) - eps)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00018) || !(eps <= 0.00015)) tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - Float64(sin(x) * sin(eps))) - cos(x)); else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00018) || ~((eps <= 0.00015))) tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x); else tmp = (-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666 * (eps ^ 3.0)) - eps)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00018], N[Not[LessEqual[eps, 0.00015]], $MachinePrecision]], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00018 \lor \neg \left(\varepsilon \leq 0.00015\right):\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \sin x \cdot \sin \varepsilon\right) - \cos x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.80000000000000011e-4 or 1.49999999999999987e-4 < eps Initial program 50.9%
cos-sum99.1%
Applied egg-rr99.1%
if -1.80000000000000011e-4 < eps < 1.49999999999999987e-4Initial program 20.6%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
associate-+l+99.7%
unpow299.7%
associate-*l*99.7%
associate-*r*99.7%
associate-*r*99.7%
distribute-rgt-out99.8%
mul-1-neg99.8%
Simplified99.8%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0025) (not (<= eps 0.0069))) (- (cos eps) (cos x)) (- (* -0.5 (* eps (* eps (cos x)))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0025) || !(eps <= 0.0069)) {
tmp = cos(eps) - cos(x);
} else {
tmp = (-0.5 * (eps * (eps * cos(x)))) - (eps * sin(x));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.0025d0)) .or. (.not. (eps <= 0.0069d0))) then
tmp = cos(eps) - cos(x)
else
tmp = ((-0.5d0) * (eps * (eps * cos(x)))) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0025) || !(eps <= 0.0069)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0025) or not (eps <= 0.0069): tmp = math.cos(eps) - math.cos(x) else: tmp = (-0.5 * (eps * (eps * math.cos(x)))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0025) || !(eps <= 0.0069)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0025) || ~((eps <= 0.0069))) tmp = cos(eps) - cos(x); else tmp = (-0.5 * (eps * (eps * cos(x)))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0025], N[Not[LessEqual[eps, 0.0069]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0025 \lor \neg \left(\varepsilon \leq 0.0069\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -0.00250000000000000005 or 0.0068999999999999999 < eps Initial program 50.9%
Taylor expanded in x around 0 53.2%
if -0.00250000000000000005 < eps < 0.0068999999999999999Initial program 20.6%
Taylor expanded in eps around 0 99.7%
mul-1-neg99.7%
unsub-neg99.7%
unpow299.7%
associate-*l*99.7%
Simplified99.7%
Final simplification74.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 37.0%
diff-cos47.1%
div-inv47.1%
metadata-eval47.1%
div-inv47.1%
+-commutative47.1%
metadata-eval47.1%
Applied egg-rr47.1%
*-commutative47.1%
+-commutative47.1%
associate--l+73.0%
*-commutative73.0%
associate-+r+73.2%
+-commutative73.2%
Simplified73.2%
Taylor expanded in x around -inf 73.2%
Final simplification73.2%
(FPCore (x eps) :precision binary64 (* (* -2.0 (sin (/ eps 2.0))) (sin (/ (+ eps (+ x x)) 2.0))))
double code(double x, double eps) {
return (-2.0 * sin((eps / 2.0))) * sin(((eps + (x + x)) / 2.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((-2.0d0) * sin((eps / 2.0d0))) * sin(((eps + (x + x)) / 2.0d0))
end function
public static double code(double x, double eps) {
return (-2.0 * Math.sin((eps / 2.0))) * Math.sin(((eps + (x + x)) / 2.0));
}
def code(x, eps): return (-2.0 * math.sin((eps / 2.0))) * math.sin(((eps + (x + x)) / 2.0))
function code(x, eps) return Float64(Float64(-2.0 * sin(Float64(eps / 2.0))) * sin(Float64(Float64(eps + Float64(x + x)) / 2.0))) end
function tmp = code(x, eps) tmp = (-2.0 * sin((eps / 2.0))) * sin(((eps + (x + x)) / 2.0)); end
code[x_, eps_] := N[(N[(-2.0 * N[Sin[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-2 \cdot \sin \left(\frac{\varepsilon}{2}\right)\right) \cdot \sin \left(\frac{\varepsilon + \left(x + x\right)}{2}\right)
\end{array}
Initial program 37.0%
add-sqr-sqrt10.9%
pow210.9%
Applied egg-rr10.9%
unpow210.9%
add-sqr-sqrt37.0%
diff-cos47.1%
+-commutative47.1%
associate-+r-73.0%
add-log-exp10.1%
+-commutative10.1%
exp-sum10.1%
+-inverses10.1%
1-exp10.1%
*-un-lft-identity10.1%
add-log-exp73.0%
+-commutative73.0%
Applied egg-rr73.0%
associate-*r*73.1%
associate-+r+73.2%
Simplified73.2%
Final simplification73.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* 0.5 eps))))
(if (or (<= x -1.05e-60) (not (<= x 1.6e-28)))
(* -2.0 (* t_0 (sin x)))
(* -2.0 (pow t_0 2.0)))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
double tmp;
if ((x <= -1.05e-60) || !(x <= 1.6e-28)) {
tmp = -2.0 * (t_0 * sin(x));
} 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 <= (-1.05d-60)) .or. (.not. (x <= 1.6d-28))) then
tmp = (-2.0d0) * (t_0 * sin(x))
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 <= -1.05e-60) || !(x <= 1.6e-28)) {
tmp = -2.0 * (t_0 * Math.sin(x));
} 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 <= -1.05e-60) or not (x <= 1.6e-28): tmp = -2.0 * (t_0 * math.sin(x)) 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 <= -1.05e-60) || !(x <= 1.6e-28)) tmp = Float64(-2.0 * Float64(t_0 * sin(x))); 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 <= -1.05e-60) || ~((x <= 1.6e-28))) tmp = -2.0 * (t_0 * sin(x)); 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, -1.05e-60], N[Not[LessEqual[x, 1.6e-28]], $MachinePrecision]], N[(-2.0 * N[(t$95$0 * N[Sin[x], $MachinePrecision]), $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 -1.05 \cdot 10^{-60} \lor \neg \left(x \leq 1.6 \cdot 10^{-28}\right):\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -1.04999999999999996e-60 or 1.59999999999999991e-28 < x Initial program 11.1%
diff-cos10.5%
div-inv10.5%
metadata-eval10.5%
div-inv10.5%
+-commutative10.5%
metadata-eval10.5%
Applied egg-rr10.5%
*-commutative10.5%
+-commutative10.5%
associate--l+52.1%
*-commutative52.1%
associate-+r+52.3%
+-commutative52.3%
Simplified52.3%
distribute-lft-in52.3%
sin-sum99.3%
Applied egg-rr99.3%
fma-def99.3%
Simplified99.3%
Taylor expanded in eps around inf 99.3%
*-commutative99.3%
*-commutative99.3%
fma-def99.3%
Simplified99.3%
Taylor expanded in eps around 0 49.2%
if -1.04999999999999996e-60 < x < 1.59999999999999991e-28Initial program 69.8%
diff-cos93.5%
div-inv93.5%
metadata-eval93.5%
div-inv93.5%
+-commutative93.5%
metadata-eval93.5%
Applied egg-rr93.5%
*-commutative93.5%
+-commutative93.5%
associate--l+99.6%
*-commutative99.6%
associate-+r+99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around 0 89.7%
Final simplification67.1%
(FPCore (x eps)
:precision binary64
(if (<= eps -5.2e-5)
(- (cos eps) (cos x))
(if (<= eps 6.5e-39)
(* eps (- (sin x)))
(* -2.0 (pow (sin (* 0.5 eps)) 2.0)))))
double code(double x, double eps) {
double tmp;
if (eps <= -5.2e-5) {
tmp = cos(eps) - cos(x);
} else if (eps <= 6.5e-39) {
tmp = eps * -sin(x);
} 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 (eps <= (-5.2d-5)) then
tmp = cos(eps) - cos(x)
else if (eps <= 6.5d-39) then
tmp = eps * -sin(x)
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 (eps <= -5.2e-5) {
tmp = Math.cos(eps) - Math.cos(x);
} else if (eps <= 6.5e-39) {
tmp = eps * -Math.sin(x);
} else {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -5.2e-5: tmp = math.cos(eps) - math.cos(x) elif eps <= 6.5e-39: tmp = eps * -math.sin(x) else: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -5.2e-5) tmp = Float64(cos(eps) - cos(x)); elseif (eps <= 6.5e-39) tmp = Float64(eps * Float64(-sin(x))); 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 (eps <= -5.2e-5) tmp = cos(eps) - cos(x); elseif (eps <= 6.5e-39) tmp = eps * -sin(x); else tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -5.2e-5], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 6.5e-39], N[(eps * (-N[Sin[x], $MachinePrecision])), $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}\;\varepsilon \leq -5.2 \cdot 10^{-5}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{elif}\;\varepsilon \leq 6.5 \cdot 10^{-39}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\end{array}
\end{array}
if eps < -5.19999999999999968e-5Initial program 55.1%
Taylor expanded in x around 0 56.9%
if -5.19999999999999968e-5 < eps < 6.50000000000000027e-39Initial program 21.7%
Taylor expanded in eps around 0 82.0%
associate-*r*82.0%
mul-1-neg82.0%
Simplified82.0%
if 6.50000000000000027e-39 < eps Initial program 41.4%
diff-cos49.1%
div-inv49.1%
metadata-eval49.1%
div-inv49.1%
+-commutative49.1%
metadata-eval49.1%
Applied egg-rr49.1%
*-commutative49.1%
+-commutative49.1%
associate--l+52.1%
*-commutative52.1%
associate-+r+52.3%
+-commutative52.3%
Simplified52.3%
Taylor expanded in x around 0 50.6%
Final simplification65.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (cos eps) (cos x))))
(if (<= eps -4.2e-7)
t_0
(if (<= eps 1e-34)
(* eps (- (sin x)))
(if (<= eps 6e-5) (* -0.5 (* eps eps)) t_0)))))
double code(double x, double eps) {
double t_0 = cos(eps) - cos(x);
double tmp;
if (eps <= -4.2e-7) {
tmp = t_0;
} else if (eps <= 1e-34) {
tmp = eps * -sin(x);
} else if (eps <= 6e-5) {
tmp = -0.5 * (eps * eps);
} 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) :: tmp
t_0 = cos(eps) - cos(x)
if (eps <= (-4.2d-7)) then
tmp = t_0
else if (eps <= 1d-34) then
tmp = eps * -sin(x)
else if (eps <= 6d-5) then
tmp = (-0.5d0) * (eps * eps)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(eps) - Math.cos(x);
double tmp;
if (eps <= -4.2e-7) {
tmp = t_0;
} else if (eps <= 1e-34) {
tmp = eps * -Math.sin(x);
} else if (eps <= 6e-5) {
tmp = -0.5 * (eps * eps);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) - math.cos(x) tmp = 0 if eps <= -4.2e-7: tmp = t_0 elif eps <= 1e-34: tmp = eps * -math.sin(x) elif eps <= 6e-5: tmp = -0.5 * (eps * eps) else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) - cos(x)) tmp = 0.0 if (eps <= -4.2e-7) tmp = t_0; elseif (eps <= 1e-34) tmp = Float64(eps * Float64(-sin(x))); elseif (eps <= 6e-5) tmp = Float64(-0.5 * Float64(eps * eps)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) - cos(x); tmp = 0.0; if (eps <= -4.2e-7) tmp = t_0; elseif (eps <= 1e-34) tmp = eps * -sin(x); elseif (eps <= 6e-5) tmp = -0.5 * (eps * eps); else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -4.2e-7], t$95$0, If[LessEqual[eps, 1e-34], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 6e-5], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon - \cos x\\
\mathbf{if}\;\varepsilon \leq -4.2 \cdot 10^{-7}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 10^{-34}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{elif}\;\varepsilon \leq 6 \cdot 10^{-5}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -4.2e-7 or 6.00000000000000015e-5 < eps Initial program 50.9%
Taylor expanded in x around 0 53.2%
if -4.2e-7 < eps < 9.99999999999999928e-35Initial program 21.7%
Taylor expanded in eps around 0 82.0%
associate-*r*82.0%
mul-1-neg82.0%
Simplified82.0%
if 9.99999999999999928e-35 < eps < 6.00000000000000015e-5Initial program 8.4%
Taylor expanded in x around 0 7.5%
Taylor expanded in eps around 0 68.6%
*-commutative68.6%
unpow268.6%
Simplified68.6%
Final simplification65.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)))
(if (<= eps -1.4e-6)
t_0
(if (<= eps 2.7e-35)
(* eps (- (sin x)))
(if (<= eps 0.000125) (* -0.5 (* eps eps)) t_0)))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double tmp;
if (eps <= -1.4e-6) {
tmp = t_0;
} else if (eps <= 2.7e-35) {
tmp = eps * -sin(x);
} else if (eps <= 0.000125) {
tmp = -0.5 * (eps * eps);
} 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) :: tmp
t_0 = cos(eps) + (-1.0d0)
if (eps <= (-1.4d-6)) then
tmp = t_0
else if (eps <= 2.7d-35) then
tmp = eps * -sin(x)
else if (eps <= 0.000125d0) then
tmp = (-0.5d0) * (eps * eps)
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 tmp;
if (eps <= -1.4e-6) {
tmp = t_0;
} else if (eps <= 2.7e-35) {
tmp = eps * -Math.sin(x);
} else if (eps <= 0.000125) {
tmp = -0.5 * (eps * eps);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 tmp = 0 if eps <= -1.4e-6: tmp = t_0 elif eps <= 2.7e-35: tmp = eps * -math.sin(x) elif eps <= 0.000125: tmp = -0.5 * (eps * eps) else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) tmp = 0.0 if (eps <= -1.4e-6) tmp = t_0; elseif (eps <= 2.7e-35) tmp = Float64(eps * Float64(-sin(x))); elseif (eps <= 0.000125) tmp = Float64(-0.5 * Float64(eps * eps)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) + -1.0; tmp = 0.0; if (eps <= -1.4e-6) tmp = t_0; elseif (eps <= 2.7e-35) tmp = eps * -sin(x); elseif (eps <= 0.000125) tmp = -0.5 * (eps * eps); else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[eps, -1.4e-6], t$95$0, If[LessEqual[eps, 2.7e-35], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 0.000125], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
\mathbf{if}\;\varepsilon \leq -1.4 \cdot 10^{-6}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 2.7 \cdot 10^{-35}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{elif}\;\varepsilon \leq 0.000125:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.39999999999999994e-6 or 1.25e-4 < eps Initial program 50.9%
Taylor expanded in x around 0 52.0%
if -1.39999999999999994e-6 < eps < 2.6999999999999997e-35Initial program 21.7%
Taylor expanded in eps around 0 82.0%
associate-*r*82.0%
mul-1-neg82.0%
Simplified82.0%
if 2.6999999999999997e-35 < eps < 1.25e-4Initial program 8.4%
Taylor expanded in x around 0 7.5%
Taylor expanded in eps around 0 68.6%
*-commutative68.6%
unpow268.6%
Simplified68.6%
Final simplification65.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.7e-32) (not (<= eps 0.000125))) (+ (cos eps) -1.0) (* -0.5 (* eps eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.7e-32) || !(eps <= 0.000125)) {
tmp = cos(eps) + -1.0;
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.7d-32)) .or. (.not. (eps <= 0.000125d0))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = (-0.5d0) * (eps * eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.7e-32) || !(eps <= 0.000125)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.7e-32) or not (eps <= 0.000125): tmp = math.cos(eps) + -1.0 else: tmp = -0.5 * (eps * eps) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.7e-32) || !(eps <= 0.000125)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(-0.5 * Float64(eps * eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.7e-32) || ~((eps <= 0.000125))) tmp = cos(eps) + -1.0; else tmp = -0.5 * (eps * eps); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.7e-32], N[Not[LessEqual[eps, 0.000125]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-32} \lor \neg \left(\varepsilon \leq 0.000125\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.69999999999999989e-32 or 1.25e-4 < eps Initial program 48.9%
Taylor expanded in x around 0 50.0%
if -1.69999999999999989e-32 < eps < 1.25e-4Initial program 21.5%
Taylor expanded in x around 0 21.4%
Taylor expanded in eps around 0 41.6%
*-commutative41.6%
unpow241.6%
Simplified41.6%
Final simplification46.4%
(FPCore (x eps) :precision binary64 (* -0.5 (* eps eps)))
double code(double x, double eps) {
return -0.5 * (eps * eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-0.5d0) * (eps * eps)
end function
public static double code(double x, double eps) {
return -0.5 * (eps * eps);
}
def code(x, eps): return -0.5 * (eps * eps)
function code(x, eps) return Float64(-0.5 * Float64(eps * eps)) end
function tmp = code(x, eps) tmp = -0.5 * (eps * eps); end
code[x_, eps_] := N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)
\end{array}
Initial program 37.0%
Taylor expanded in x around 0 37.6%
Taylor expanded in eps around 0 20.1%
*-commutative20.1%
unpow220.1%
Simplified20.1%
Final simplification20.1%
(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 37.0%
Taylor expanded in x around 0 37.6%
Taylor expanded in eps around 0 10.9%
Final simplification10.9%
herbie shell --seed 2023257
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))