
(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 14 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 x) (- (sin eps)))))
(if (<= eps -1100.0)
(- (fma (cos x) (cos eps) t_0) (cos x))
(if (<= eps 0.45)
(* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5))))
(fma (cos x) (cos eps) (- t_0 (cos x)))))))
double code(double x, double eps) {
double t_0 = sin(x) * -sin(eps);
double tmp;
if (eps <= -1100.0) {
tmp = fma(cos(x), cos(eps), t_0) - cos(x);
} else if (eps <= 0.45) {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = fma(cos(x), cos(eps), (t_0 - cos(x)));
}
return tmp;
}
function code(x, eps) t_0 = Float64(sin(x) * Float64(-sin(eps))) tmp = 0.0 if (eps <= -1100.0) tmp = Float64(fma(cos(x), cos(eps), t_0) - cos(x)); elseif (eps <= 0.45) tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = fma(cos(x), cos(eps), Float64(t_0 - cos(x))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[eps, -1100.0], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + t$95$0), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.45], 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], N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(t$95$0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin x \cdot \left(-\sin \varepsilon\right)\\
\mathbf{if}\;\varepsilon \leq -1100:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, t_0\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 0.45:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, t_0 - \cos x\right)\\
\end{array}
\end{array}
if eps < -1100Initial program 48.8%
cos-sum98.4%
cancel-sign-sub-inv98.4%
fma-def98.4%
Applied egg-rr98.4%
if -1100 < eps < 0.450000000000000011Initial program 26.9%
diff-cos52.0%
div-inv52.0%
associate--l+52.0%
metadata-eval52.0%
div-inv52.0%
+-commutative52.0%
associate-+l+51.9%
metadata-eval51.9%
Applied egg-rr51.9%
associate-*r*51.9%
*-commutative51.9%
*-commutative51.9%
+-commutative51.9%
count-251.9%
fma-def51.9%
sub-neg51.9%
mul-1-neg51.9%
+-commutative51.9%
associate-+r+99.8%
mul-1-neg99.8%
sub-neg99.8%
+-inverses99.8%
remove-double-neg99.8%
mul-1-neg99.8%
sub-neg99.8%
neg-sub099.8%
mul-1-neg99.8%
remove-double-neg99.8%
Simplified99.8%
if 0.450000000000000011 < eps Initial program 46.5%
sub-neg46.5%
cos-sum98.9%
associate-+l-98.9%
fma-neg99.0%
Applied egg-rr99.0%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (cos x) (cos eps))))
(if (<= eps -1100.0)
(- (- t_0 (* (sin x) (sin eps))) (cos x))
(if (<= eps 0.45)
(* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5))))
(- t_0 (fma (sin eps) (sin x) (cos x)))))))
double code(double x, double eps) {
double t_0 = cos(x) * cos(eps);
double tmp;
if (eps <= -1100.0) {
tmp = (t_0 - (sin(x) * sin(eps))) - cos(x);
} else if (eps <= 0.45) {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = t_0 - fma(sin(eps), sin(x), cos(x));
}
return tmp;
}
function code(x, eps) t_0 = Float64(cos(x) * cos(eps)) tmp = 0.0 if (eps <= -1100.0) tmp = Float64(Float64(t_0 - Float64(sin(x) * sin(eps))) - cos(x)); elseif (eps <= 0.45) tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = Float64(t_0 - fma(sin(eps), sin(x), cos(x))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -1100.0], N[(N[(t$95$0 - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.45], 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], N[(t$95$0 - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision] + N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \cos \varepsilon\\
\mathbf{if}\;\varepsilon \leq -1100:\\
\;\;\;\;\left(t_0 - \sin x \cdot \sin \varepsilon\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 0.45:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;t_0 - \mathsf{fma}\left(\sin \varepsilon, \sin x, \cos x\right)\\
\end{array}
\end{array}
if eps < -1100Initial program 48.8%
cos-sum98.4%
Applied egg-rr98.4%
if -1100 < eps < 0.450000000000000011Initial program 26.9%
diff-cos52.0%
div-inv52.0%
associate--l+52.0%
metadata-eval52.0%
div-inv52.0%
+-commutative52.0%
associate-+l+51.9%
metadata-eval51.9%
Applied egg-rr51.9%
associate-*r*51.9%
*-commutative51.9%
*-commutative51.9%
+-commutative51.9%
count-251.9%
fma-def51.9%
sub-neg51.9%
mul-1-neg51.9%
+-commutative51.9%
associate-+r+99.8%
mul-1-neg99.8%
sub-neg99.8%
+-inverses99.8%
remove-double-neg99.8%
mul-1-neg99.8%
sub-neg99.8%
neg-sub099.8%
mul-1-neg99.8%
remove-double-neg99.8%
Simplified99.8%
if 0.450000000000000011 < eps Initial program 46.5%
sub-neg46.5%
cos-sum98.9%
associate-+l-98.9%
fma-neg99.0%
Applied egg-rr99.0%
fma-neg98.9%
*-commutative98.9%
*-commutative98.9%
fma-neg99.0%
remove-double-neg99.0%
Simplified99.0%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (<= eps -1100.0)
(- (fma (cos x) (cos eps) (* (sin x) (- (sin eps)))) (cos x))
(if (<= eps 0.45)
(* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5))))
(- (* (cos x) (cos eps)) (fma (sin eps) (sin x) (cos x))))))
double code(double x, double eps) {
double tmp;
if (eps <= -1100.0) {
tmp = fma(cos(x), cos(eps), (sin(x) * -sin(eps))) - cos(x);
} else if (eps <= 0.45) {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = (cos(x) * cos(eps)) - fma(sin(eps), sin(x), cos(x));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -1100.0) tmp = Float64(fma(cos(x), cos(eps), Float64(sin(x) * Float64(-sin(eps)))) - cos(x)); elseif (eps <= 0.45) tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = Float64(Float64(cos(x) * cos(eps)) - fma(sin(eps), sin(x), cos(x))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -1100.0], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.45], 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], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision] + N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1100:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin x \cdot \left(-\sin \varepsilon\right)\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 0.45:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \mathsf{fma}\left(\sin \varepsilon, \sin x, \cos x\right)\\
\end{array}
\end{array}
if eps < -1100Initial program 48.8%
cos-sum98.4%
cancel-sign-sub-inv98.4%
fma-def98.4%
Applied egg-rr98.4%
if -1100 < eps < 0.450000000000000011Initial program 26.9%
diff-cos52.0%
div-inv52.0%
associate--l+52.0%
metadata-eval52.0%
div-inv52.0%
+-commutative52.0%
associate-+l+51.9%
metadata-eval51.9%
Applied egg-rr51.9%
associate-*r*51.9%
*-commutative51.9%
*-commutative51.9%
+-commutative51.9%
count-251.9%
fma-def51.9%
sub-neg51.9%
mul-1-neg51.9%
+-commutative51.9%
associate-+r+99.8%
mul-1-neg99.8%
sub-neg99.8%
+-inverses99.8%
remove-double-neg99.8%
mul-1-neg99.8%
sub-neg99.8%
neg-sub099.8%
mul-1-neg99.8%
remove-double-neg99.8%
Simplified99.8%
if 0.450000000000000011 < eps Initial program 46.5%
sub-neg46.5%
cos-sum98.9%
associate-+l-98.9%
fma-neg99.0%
Applied egg-rr99.0%
fma-neg98.9%
*-commutative98.9%
*-commutative98.9%
fma-neg99.0%
remove-double-neg99.0%
Simplified99.0%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1100.0) (not (<= eps 0.45))) (- (- (* (cos x) (cos eps)) (* (sin x) (sin eps))) (cos x)) (* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1100.0) || !(eps <= 0.45)) {
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x);
} else {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -1100.0) || !(eps <= 0.45)) tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - Float64(sin(x) * sin(eps))) - cos(x)); else tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -1100.0], N[Not[LessEqual[eps, 0.45]], $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[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}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1100 \lor \neg \left(\varepsilon \leq 0.45\right):\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \sin x \cdot \sin \varepsilon\right) - \cos x\\
\mathbf{else}:\\
\;\;\;\;\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}
\end{array}
if eps < -1100 or 0.450000000000000011 < eps Initial program 47.8%
cos-sum98.6%
Applied egg-rr98.6%
if -1100 < eps < 0.450000000000000011Initial program 26.9%
diff-cos52.0%
div-inv52.0%
associate--l+52.0%
metadata-eval52.0%
div-inv52.0%
+-commutative52.0%
associate-+l+51.9%
metadata-eval51.9%
Applied egg-rr51.9%
associate-*r*51.9%
*-commutative51.9%
*-commutative51.9%
+-commutative51.9%
count-251.9%
fma-def51.9%
sub-neg51.9%
mul-1-neg51.9%
+-commutative51.9%
associate-+r+99.8%
mul-1-neg99.8%
sub-neg99.8%
+-inverses99.8%
remove-double-neg99.8%
mul-1-neg99.8%
sub-neg99.8%
neg-sub099.8%
mul-1-neg99.8%
remove-double-neg99.8%
Simplified99.8%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0038) (not (<= eps 0.0026))) (- (cos eps) (cos x)) (- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0038) || !(eps <= 0.0026)) {
tmp = cos(eps) - 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 <= (-0.0038d0)) .or. (.not. (eps <= 0.0026d0))) then
tmp = cos(eps) - 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 <= -0.0038) || !(eps <= 0.0026)) {
tmp = Math.cos(eps) - 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 <= -0.0038) or not (eps <= 0.0026): tmp = math.cos(eps) - 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 <= -0.0038) || !(eps <= 0.0026)) tmp = Float64(cos(eps) - 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 <= -0.0038) || ~((eps <= 0.0026))) tmp = cos(eps) - 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, -0.0038], N[Not[LessEqual[eps, 0.0026]], $MachinePrecision]], N[(N[Cos[eps], $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 -0.0038 \lor \neg \left(\varepsilon \leq 0.0026\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -0.00379999999999999999 or 0.0025999999999999999 < eps Initial program 48.6%
Taylor expanded in x around 0 50.6%
if -0.00379999999999999999 < eps < 0.0025999999999999999Initial program 25.9%
Taylor expanded in eps around 0 99.5%
+-commutative99.5%
mul-1-neg99.5%
unsub-neg99.5%
associate-*r*99.5%
*-commutative99.5%
Simplified99.5%
Final simplification76.0%
(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 36.8%
diff-cos49.1%
div-inv49.1%
associate--l+49.1%
metadata-eval49.1%
div-inv49.1%
+-commutative49.1%
associate-+l+49.1%
metadata-eval49.1%
Applied egg-rr49.1%
associate-*r*49.1%
*-commutative49.1%
*-commutative49.1%
+-commutative49.1%
count-249.1%
fma-def49.1%
sub-neg49.1%
mul-1-neg49.1%
+-commutative49.1%
associate-+r+75.1%
mul-1-neg75.1%
sub-neg75.1%
+-inverses75.1%
remove-double-neg75.1%
mul-1-neg75.1%
sub-neg75.1%
neg-sub075.1%
mul-1-neg75.1%
remove-double-neg75.1%
Simplified75.1%
Final simplification75.1%
(FPCore (x eps) :precision binary64 (if (or (<= x -4e-31) (not (<= x 1.15e-15))) (* (sin x) (* -2.0 (sin (* eps 0.5)))) (* -2.0 (* (sin (* 0.5 (+ x (- eps x)))) (sin (* 0.5 (+ eps (+ x x))))))))
double code(double x, double eps) {
double tmp;
if ((x <= -4e-31) || !(x <= 1.15e-15)) {
tmp = sin(x) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = -2.0 * (sin((0.5 * (x + (eps - x)))) * sin((0.5 * (eps + (x + x)))));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-4d-31)) .or. (.not. (x <= 1.15d-15))) then
tmp = sin(x) * ((-2.0d0) * sin((eps * 0.5d0)))
else
tmp = (-2.0d0) * (sin((0.5d0 * (x + (eps - x)))) * sin((0.5d0 * (eps + (x + x)))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -4e-31) || !(x <= 1.15e-15)) {
tmp = Math.sin(x) * (-2.0 * Math.sin((eps * 0.5)));
} else {
tmp = -2.0 * (Math.sin((0.5 * (x + (eps - x)))) * Math.sin((0.5 * (eps + (x + x)))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -4e-31) or not (x <= 1.15e-15): tmp = math.sin(x) * (-2.0 * math.sin((eps * 0.5))) else: tmp = -2.0 * (math.sin((0.5 * (x + (eps - x)))) * math.sin((0.5 * (eps + (x + x))))) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -4e-31) || !(x <= 1.15e-15)) tmp = Float64(sin(x) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = Float64(-2.0 * Float64(sin(Float64(0.5 * Float64(x + Float64(eps - x)))) * sin(Float64(0.5 * Float64(eps + Float64(x + x)))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -4e-31) || ~((x <= 1.15e-15))) tmp = sin(x) * (-2.0 * sin((eps * 0.5))); else tmp = -2.0 * (sin((0.5 * (x + (eps - x)))) * sin((0.5 * (eps + (x + x))))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -4e-31], N[Not[LessEqual[x, 1.15e-15]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[Sin[N[(0.5 * N[(x + N[(eps - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-31} \lor \neg \left(x \leq 1.15 \cdot 10^{-15}\right):\\
\;\;\;\;\sin x \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\sin \left(0.5 \cdot \left(x + \left(\varepsilon - x\right)\right)\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)\right)\\
\end{array}
\end{array}
if x < -4e-31 or 1.14999999999999995e-15 < x Initial program 8.7%
diff-cos6.8%
div-inv6.8%
associate--l+6.8%
metadata-eval6.8%
div-inv6.8%
+-commutative6.8%
associate-+l+6.8%
metadata-eval6.8%
Applied egg-rr6.8%
associate-*r*6.8%
*-commutative6.8%
*-commutative6.8%
+-commutative6.8%
count-26.8%
fma-def6.8%
sub-neg6.8%
mul-1-neg6.8%
+-commutative6.8%
associate-+r+52.8%
mul-1-neg52.8%
sub-neg52.8%
+-inverses52.8%
remove-double-neg52.8%
mul-1-neg52.8%
sub-neg52.8%
neg-sub052.8%
mul-1-neg52.8%
remove-double-neg52.8%
Simplified52.8%
Taylor expanded in eps around 0 53.7%
if -4e-31 < x < 1.14999999999999995e-15Initial program 67.6%
diff-cos95.5%
*-commutative95.5%
div-inv95.5%
associate--l+95.5%
metadata-eval95.5%
div-inv95.5%
+-commutative95.5%
associate-+l+95.4%
metadata-eval95.4%
Applied egg-rr95.4%
Final simplification73.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -3e-31) (not (<= x 3.4e-16)))
(* (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 <= -3e-31) || !(x <= 3.4e-16)) {
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 <= (-3d-31)) .or. (.not. (x <= 3.4d-16))) 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 <= -3e-31) || !(x <= 3.4e-16)) {
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 <= -3e-31) or not (x <= 3.4e-16): 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 <= -3e-31) || !(x <= 3.4e-16)) 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 <= -3e-31) || ~((x <= 3.4e-16))) 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, -3e-31], N[Not[LessEqual[x, 3.4e-16]], $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 \cdot 10^{-31} \lor \neg \left(x \leq 3.4 \cdot 10^{-16}\right):\\
\;\;\;\;\sin x \cdot \left(-2 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -2.99999999999999981e-31 or 3.4e-16 < x Initial program 8.7%
diff-cos6.8%
div-inv6.8%
associate--l+6.8%
metadata-eval6.8%
div-inv6.8%
+-commutative6.8%
associate-+l+6.8%
metadata-eval6.8%
Applied egg-rr6.8%
associate-*r*6.8%
*-commutative6.8%
*-commutative6.8%
+-commutative6.8%
count-26.8%
fma-def6.8%
sub-neg6.8%
mul-1-neg6.8%
+-commutative6.8%
associate-+r+52.8%
mul-1-neg52.8%
sub-neg52.8%
+-inverses52.8%
remove-double-neg52.8%
mul-1-neg52.8%
sub-neg52.8%
neg-sub052.8%
mul-1-neg52.8%
remove-double-neg52.8%
Simplified52.8%
Taylor expanded in eps around 0 53.7%
if -2.99999999999999981e-31 < x < 3.4e-16Initial program 67.6%
diff-cos95.5%
div-inv95.5%
associate--l+95.5%
metadata-eval95.5%
div-inv95.5%
+-commutative95.5%
associate-+l+95.4%
metadata-eval95.4%
Applied egg-rr95.4%
associate-*r*95.4%
*-commutative95.4%
*-commutative95.4%
+-commutative95.4%
count-295.4%
fma-def95.4%
sub-neg95.4%
mul-1-neg95.4%
+-commutative95.4%
associate-+r+99.6%
mul-1-neg99.6%
sub-neg99.6%
+-inverses99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
neg-sub099.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 93.1%
Final simplification72.5%
(FPCore (x eps) :precision binary64 (if (or (<= x -2.4e-31) (not (<= x 3.5e-16))) (* eps (- (sin x))) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -2.4e-31) || !(x <= 3.5e-16)) {
tmp = eps * -sin(x);
} else {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-2.4d-31)) .or. (.not. (x <= 3.5d-16))) then
tmp = eps * -sin(x)
else
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -2.4e-31) || !(x <= 3.5e-16)) {
tmp = eps * -Math.sin(x);
} else {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -2.4e-31) or not (x <= 3.5e-16): tmp = eps * -math.sin(x) else: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -2.4e-31) || !(x <= 3.5e-16)) tmp = Float64(eps * Float64(-sin(x))); else tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -2.4e-31) || ~((x <= 3.5e-16))) tmp = eps * -sin(x); else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -2.4e-31], N[Not[LessEqual[x, 3.5e-16]], $MachinePrecision]], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-31} \lor \neg \left(x \leq 3.5 \cdot 10^{-16}\right):\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if x < -2.4e-31 or 3.50000000000000017e-16 < x Initial program 8.7%
Taylor expanded in eps around 0 48.7%
mul-1-neg48.7%
*-commutative48.7%
distribute-rgt-neg-in48.7%
Simplified48.7%
if -2.4e-31 < x < 3.50000000000000017e-16Initial program 67.6%
diff-cos95.5%
div-inv95.5%
associate--l+95.5%
metadata-eval95.5%
div-inv95.5%
+-commutative95.5%
associate-+l+95.4%
metadata-eval95.4%
Applied egg-rr95.4%
associate-*r*95.4%
*-commutative95.4%
*-commutative95.4%
+-commutative95.4%
count-295.4%
fma-def95.4%
sub-neg95.4%
mul-1-neg95.4%
+-commutative95.4%
associate-+r+99.6%
mul-1-neg99.6%
sub-neg99.6%
+-inverses99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
neg-sub099.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 93.1%
Final simplification69.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (cos eps) (cos x))))
(if (<= eps -1.5e-10)
t_0
(if (<= eps 5.1e-142)
(* eps (- (sin x)))
(if (<= eps 4.5e-16) (* -0.5 (pow eps 2.0)) t_0)))))
double code(double x, double eps) {
double t_0 = cos(eps) - cos(x);
double tmp;
if (eps <= -1.5e-10) {
tmp = t_0;
} else if (eps <= 5.1e-142) {
tmp = eps * -sin(x);
} else if (eps <= 4.5e-16) {
tmp = -0.5 * pow(eps, 2.0);
} 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 <= (-1.5d-10)) then
tmp = t_0
else if (eps <= 5.1d-142) then
tmp = eps * -sin(x)
else if (eps <= 4.5d-16) then
tmp = (-0.5d0) * (eps ** 2.0d0)
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 <= -1.5e-10) {
tmp = t_0;
} else if (eps <= 5.1e-142) {
tmp = eps * -Math.sin(x);
} else if (eps <= 4.5e-16) {
tmp = -0.5 * Math.pow(eps, 2.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) - math.cos(x) tmp = 0 if eps <= -1.5e-10: tmp = t_0 elif eps <= 5.1e-142: tmp = eps * -math.sin(x) elif eps <= 4.5e-16: tmp = -0.5 * math.pow(eps, 2.0) else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) - cos(x)) tmp = 0.0 if (eps <= -1.5e-10) tmp = t_0; elseif (eps <= 5.1e-142) tmp = Float64(eps * Float64(-sin(x))); elseif (eps <= 4.5e-16) tmp = Float64(-0.5 * (eps ^ 2.0)); 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 <= -1.5e-10) tmp = t_0; elseif (eps <= 5.1e-142) tmp = eps * -sin(x); elseif (eps <= 4.5e-16) tmp = -0.5 * (eps ^ 2.0); 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, -1.5e-10], t$95$0, If[LessEqual[eps, 5.1e-142], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 4.5e-16], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon - \cos x\\
\mathbf{if}\;\varepsilon \leq -1.5 \cdot 10^{-10}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 5.1 \cdot 10^{-142}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{elif}\;\varepsilon \leq 4.5 \cdot 10^{-16}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.5e-10 or 4.5000000000000002e-16 < eps Initial program 48.0%
Taylor expanded in x around 0 49.5%
if -1.5e-10 < eps < 5.1000000000000001e-142Initial program 30.9%
Taylor expanded in eps around 0 85.3%
mul-1-neg85.3%
*-commutative85.3%
distribute-rgt-neg-in85.3%
Simplified85.3%
if 5.1000000000000001e-142 < eps < 4.5000000000000002e-16Initial program 5.2%
Taylor expanded in x around 0 5.2%
Taylor expanded in eps around 0 61.4%
Final simplification65.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)) (t_1 (* -0.5 (pow eps 2.0))))
(if (<= eps -0.00014)
t_0
(if (<= eps -4.8e-133)
t_1
(if (<= eps 1.4e-144) (* eps (- x)) (if (<= eps 4.5e-16) 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 <= -0.00014) {
tmp = t_0;
} else if (eps <= -4.8e-133) {
tmp = t_1;
} else if (eps <= 1.4e-144) {
tmp = eps * -x;
} else if (eps <= 4.5e-16) {
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 <= (-0.00014d0)) then
tmp = t_0
else if (eps <= (-4.8d-133)) then
tmp = t_1
else if (eps <= 1.4d-144) then
tmp = eps * -x
else if (eps <= 4.5d-16) 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 <= -0.00014) {
tmp = t_0;
} else if (eps <= -4.8e-133) {
tmp = t_1;
} else if (eps <= 1.4e-144) {
tmp = eps * -x;
} else if (eps <= 4.5e-16) {
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 <= -0.00014: tmp = t_0 elif eps <= -4.8e-133: tmp = t_1 elif eps <= 1.4e-144: tmp = eps * -x elif eps <= 4.5e-16: 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 <= -0.00014) tmp = t_0; elseif (eps <= -4.8e-133) tmp = t_1; elseif (eps <= 1.4e-144) tmp = Float64(eps * Float64(-x)); elseif (eps <= 4.5e-16) 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 <= -0.00014) tmp = t_0; elseif (eps <= -4.8e-133) tmp = t_1; elseif (eps <= 1.4e-144) tmp = eps * -x; elseif (eps <= 4.5e-16) 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, -0.00014], t$95$0, If[LessEqual[eps, -4.8e-133], t$95$1, If[LessEqual[eps, 1.4e-144], N[(eps * (-x)), $MachinePrecision], If[LessEqual[eps, 4.5e-16], 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 -0.00014:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -4.8 \cdot 10^{-133}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 1.4 \cdot 10^{-144}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{elif}\;\varepsilon \leq 4.5 \cdot 10^{-16}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.3999999999999999e-4 or 4.5000000000000002e-16 < eps Initial program 48.2%
Taylor expanded in x around 0 47.9%
if -1.3999999999999999e-4 < eps < -4.8e-133 or 1.39999999999999999e-144 < eps < 4.5000000000000002e-16Initial program 6.3%
Taylor expanded in x around 0 5.5%
Taylor expanded in eps around 0 51.5%
if -4.8e-133 < eps < 1.39999999999999999e-144Initial program 44.0%
Taylor expanded in eps around 0 97.1%
mul-1-neg97.1%
*-commutative97.1%
distribute-rgt-neg-in97.1%
Simplified97.1%
Taylor expanded in x around 0 56.2%
mul-1-neg56.2%
distribute-rgt-neg-in56.2%
Simplified56.2%
Final simplification51.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)))
(if (<= eps -1.5e-10)
t_0
(if (<= eps 3e-143)
(* eps (- (sin x)))
(if (<= eps 4.5e-16) (* -0.5 (pow eps 2.0)) t_0)))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double tmp;
if (eps <= -1.5e-10) {
tmp = t_0;
} else if (eps <= 3e-143) {
tmp = eps * -sin(x);
} else if (eps <= 4.5e-16) {
tmp = -0.5 * pow(eps, 2.0);
} 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.5d-10)) then
tmp = t_0
else if (eps <= 3d-143) then
tmp = eps * -sin(x)
else if (eps <= 4.5d-16) then
tmp = (-0.5d0) * (eps ** 2.0d0)
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.5e-10) {
tmp = t_0;
} else if (eps <= 3e-143) {
tmp = eps * -Math.sin(x);
} else if (eps <= 4.5e-16) {
tmp = -0.5 * Math.pow(eps, 2.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 tmp = 0 if eps <= -1.5e-10: tmp = t_0 elif eps <= 3e-143: tmp = eps * -math.sin(x) elif eps <= 4.5e-16: tmp = -0.5 * math.pow(eps, 2.0) else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) tmp = 0.0 if (eps <= -1.5e-10) tmp = t_0; elseif (eps <= 3e-143) tmp = Float64(eps * Float64(-sin(x))); elseif (eps <= 4.5e-16) tmp = Float64(-0.5 * (eps ^ 2.0)); 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.5e-10) tmp = t_0; elseif (eps <= 3e-143) tmp = eps * -sin(x); elseif (eps <= 4.5e-16) tmp = -0.5 * (eps ^ 2.0); 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.5e-10], t$95$0, If[LessEqual[eps, 3e-143], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 4.5e-16], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
\mathbf{if}\;\varepsilon \leq -1.5 \cdot 10^{-10}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 3 \cdot 10^{-143}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{elif}\;\varepsilon \leq 4.5 \cdot 10^{-16}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.5e-10 or 4.5000000000000002e-16 < eps Initial program 48.0%
Taylor expanded in x around 0 47.3%
if -1.5e-10 < eps < 2.99999999999999985e-143Initial program 30.9%
Taylor expanded in eps around 0 85.3%
mul-1-neg85.3%
*-commutative85.3%
distribute-rgt-neg-in85.3%
Simplified85.3%
if 2.99999999999999985e-143 < eps < 4.5000000000000002e-16Initial program 5.2%
Taylor expanded in x around 0 5.2%
Taylor expanded in eps around 0 61.4%
Final simplification64.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.8e-15) (not (<= eps 7.8e-15))) (+ (cos eps) -1.0) (* eps (- x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.8e-15) || !(eps <= 7.8e-15)) {
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 <= (-4.8d-15)) .or. (.not. (eps <= 7.8d-15))) 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 <= -4.8e-15) || !(eps <= 7.8e-15)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * -x;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4.8e-15) or not (eps <= 7.8e-15): tmp = math.cos(eps) + -1.0 else: tmp = eps * -x return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -4.8e-15) || !(eps <= 7.8e-15)) 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 <= -4.8e-15) || ~((eps <= 7.8e-15))) tmp = cos(eps) + -1.0; else tmp = eps * -x; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.8e-15], N[Not[LessEqual[eps, 7.8e-15]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(eps * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.8 \cdot 10^{-15} \lor \neg \left(\varepsilon \leq 7.8 \cdot 10^{-15}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\end{array}
\end{array}
if eps < -4.7999999999999999e-15 or 7.80000000000000053e-15 < eps Initial program 48.4%
Taylor expanded in x around 0 47.6%
if -4.7999999999999999e-15 < eps < 7.80000000000000053e-15Initial program 25.6%
Taylor expanded in eps around 0 75.3%
mul-1-neg75.3%
*-commutative75.3%
distribute-rgt-neg-in75.3%
Simplified75.3%
Taylor expanded in x around 0 35.1%
mul-1-neg35.1%
distribute-rgt-neg-in35.1%
Simplified35.1%
Final simplification41.3%
(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 36.8%
Taylor expanded in eps around 0 40.0%
mul-1-neg40.0%
*-commutative40.0%
distribute-rgt-neg-in40.0%
Simplified40.0%
Taylor expanded in x around 0 19.4%
mul-1-neg19.4%
distribute-rgt-neg-in19.4%
Simplified19.4%
Final simplification19.4%
herbie shell --seed 2023306
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))