
(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 16 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
(if (<= eps -5.2e-5)
(fma (sin x) (- (sin eps)) (- (* (cos x) (cos eps)) (cos x)))
(if (<= eps 2.5e-5)
(* -2.0 (* (+ (sin x) (* 0.5 (* eps (cos x)))) (sin (* eps 0.5))))
(fma (cos x) (cos eps) (- (- (cos x)) (* (sin x) (sin eps)))))))
double code(double x, double eps) {
double tmp;
if (eps <= -5.2e-5) {
tmp = fma(sin(x), -sin(eps), ((cos(x) * cos(eps)) - cos(x)));
} else if (eps <= 2.5e-5) {
tmp = -2.0 * ((sin(x) + (0.5 * (eps * cos(x)))) * sin((eps * 0.5)));
} else {
tmp = fma(cos(x), cos(eps), (-cos(x) - (sin(x) * sin(eps))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -5.2e-5) tmp = fma(sin(x), Float64(-sin(eps)), Float64(Float64(cos(x) * cos(eps)) - cos(x))); elseif (eps <= 2.5e-5) tmp = Float64(-2.0 * Float64(Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x)))) * sin(Float64(eps * 0.5)))); else tmp = fma(cos(x), cos(eps), Float64(Float64(-cos(x)) - Float64(sin(x) * sin(eps)))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -5.2e-5], N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.5e-5], N[(-2.0 * N[(N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[((-N[Cos[x], $MachinePrecision]) - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5.2 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \cos \varepsilon - \cos x\right)\\
\mathbf{elif}\;\varepsilon \leq 2.5 \cdot 10^{-5}:\\
\;\;\;\;-2 \cdot \left(\left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \left(-\cos x\right) - \sin x \cdot \sin \varepsilon\right)\\
\end{array}
\end{array}
if eps < -5.19999999999999968e-5Initial program 53.6%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
associate--l+98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
fma-def98.8%
*-rgt-identity98.8%
distribute-lft-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
Simplified98.7%
distribute-lft-in98.8%
Applied egg-rr98.8%
if -5.19999999999999968e-5 < eps < 2.50000000000000012e-5Initial program 18.6%
diff-cos35.2%
div-inv35.2%
metadata-eval35.2%
div-inv35.2%
+-commutative35.2%
metadata-eval35.2%
Applied egg-rr35.2%
*-commutative35.2%
+-commutative35.2%
associate--l+99.2%
+-inverses99.2%
distribute-lft-in99.2%
metadata-eval99.2%
*-commutative99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.7%
if 2.50000000000000012e-5 < eps Initial program 53.0%
sub-neg53.0%
cos-sum99.1%
associate-+l-99.1%
fma-neg99.2%
Applied egg-rr99.2%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (fma (sin x) (- (sin eps)) (* (cos x) (/ (pow (sin eps) 2.0) (- -1.0 (cos eps))))))
double code(double x, double eps) {
return fma(sin(x), -sin(eps), (cos(x) * (pow(sin(eps), 2.0) / (-1.0 - cos(eps)))));
}
function code(x, eps) return fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64((sin(eps) ^ 2.0) / Float64(-1.0 - cos(eps))))) end
code[x_, eps_] := N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision] / N[(-1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \frac{{\sin \varepsilon}^{2}}{-1 - \cos \varepsilon}\right)
\end{array}
Initial program 36.0%
cos-sum59.3%
cancel-sign-sub-inv59.3%
fma-def59.3%
Applied egg-rr59.3%
Taylor expanded in x around inf 59.3%
neg-mul-159.3%
associate--l+90.8%
*-commutative90.8%
distribute-rgt-neg-in90.8%
fma-def90.8%
*-rgt-identity90.8%
distribute-lft-out--90.8%
sub-neg90.8%
metadata-eval90.8%
+-commutative90.8%
Simplified90.8%
flip-+90.5%
metadata-eval90.5%
1-sub-cos99.2%
pow299.2%
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -5.4e-5) (not (<= eps 3.3e-5))) (fma (cos x) (cos eps) (- (- (cos x)) (* (sin x) (sin eps)))) (* -2.0 (* (+ (sin x) (* 0.5 (* eps (cos x)))) (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -5.4e-5) || !(eps <= 3.3e-5)) {
tmp = fma(cos(x), cos(eps), (-cos(x) - (sin(x) * sin(eps))));
} else {
tmp = -2.0 * ((sin(x) + (0.5 * (eps * cos(x)))) * sin((eps * 0.5)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -5.4e-5) || !(eps <= 3.3e-5)) tmp = fma(cos(x), cos(eps), Float64(Float64(-cos(x)) - Float64(sin(x) * sin(eps)))); else tmp = Float64(-2.0 * Float64(Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x)))) * sin(Float64(eps * 0.5)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -5.4e-5], N[Not[LessEqual[eps, 3.3e-5]], $MachinePrecision]], N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[((-N[Cos[x], $MachinePrecision]) - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5.4 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 3.3 \cdot 10^{-5}\right):\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \left(-\cos x\right) - \sin x \cdot \sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -5.3999999999999998e-5 or 3.3000000000000003e-5 < eps Initial program 53.3%
sub-neg53.3%
cos-sum98.9%
associate-+l-98.8%
fma-neg99.0%
Applied egg-rr99.0%
if -5.3999999999999998e-5 < eps < 3.3000000000000003e-5Initial program 18.6%
diff-cos35.2%
div-inv35.2%
metadata-eval35.2%
div-inv35.2%
+-commutative35.2%
metadata-eval35.2%
Applied egg-rr35.2%
*-commutative35.2%
+-commutative35.2%
associate--l+99.2%
+-inverses99.2%
distribute-lft-in99.2%
metadata-eval99.2%
*-commutative99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.7%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (sin eps))))
(if (<= eps -4.9e-5)
(fma (sin x) t_0 (* (cos x) (+ -1.0 (cos eps))))
(if (<= eps 4.7e-5)
(* -2.0 (* (+ (sin x) (* 0.5 (* eps (cos x)))) (sin (* eps 0.5))))
(- (fma (cos x) (cos eps) (* (sin x) t_0)) (cos x))))))
double code(double x, double eps) {
double t_0 = -sin(eps);
double tmp;
if (eps <= -4.9e-5) {
tmp = fma(sin(x), t_0, (cos(x) * (-1.0 + cos(eps))));
} else if (eps <= 4.7e-5) {
tmp = -2.0 * ((sin(x) + (0.5 * (eps * cos(x)))) * sin((eps * 0.5)));
} else {
tmp = fma(cos(x), cos(eps), (sin(x) * t_0)) - cos(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64(-sin(eps)) tmp = 0.0 if (eps <= -4.9e-5) tmp = fma(sin(x), t_0, Float64(cos(x) * Float64(-1.0 + cos(eps)))); elseif (eps <= 4.7e-5) tmp = Float64(-2.0 * Float64(Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x)))) * sin(Float64(eps * 0.5)))); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(x) * t_0)) - cos(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = (-N[Sin[eps], $MachinePrecision])}, If[LessEqual[eps, -4.9e-5], N[(N[Sin[x], $MachinePrecision] * t$95$0 + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.7e-5], N[(-2.0 * N[(N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -4.9 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\sin x, t_0, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 4.7 \cdot 10^{-5}:\\
\;\;\;\;-2 \cdot \left(\left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin x \cdot t_0\right) - \cos x\\
\end{array}
\end{array}
if eps < -4.9e-5Initial program 53.6%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
associate--l+98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
fma-def98.8%
*-rgt-identity98.8%
distribute-lft-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
Simplified98.7%
if -4.9e-5 < eps < 4.69999999999999972e-5Initial program 18.6%
diff-cos35.2%
div-inv35.2%
metadata-eval35.2%
div-inv35.2%
+-commutative35.2%
metadata-eval35.2%
Applied egg-rr35.2%
*-commutative35.2%
+-commutative35.2%
associate--l+99.2%
+-inverses99.2%
distribute-lft-in99.2%
metadata-eval99.2%
*-commutative99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.7%
if 4.69999999999999972e-5 < eps Initial program 53.0%
cos-sum99.1%
cancel-sign-sub-inv99.1%
fma-def99.1%
Applied egg-rr99.1%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (<= eps -2.85e-5)
(fma (sin x) (- (sin eps)) (* (cos x) (+ -1.0 (cos eps))))
(if (<= eps 4.9e-5)
(* -2.0 (* (+ (sin x) (* 0.5 (* eps (cos x)))) (sin (* eps 0.5))))
(- (- (* (cos x) (cos eps)) (* (sin x) (sin eps))) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -2.85e-5) {
tmp = fma(sin(x), -sin(eps), (cos(x) * (-1.0 + cos(eps))));
} else if (eps <= 4.9e-5) {
tmp = -2.0 * ((sin(x) + (0.5 * (eps * cos(x)))) * sin((eps * 0.5)));
} else {
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -2.85e-5) tmp = fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(-1.0 + cos(eps)))); elseif (eps <= 4.9e-5) tmp = Float64(-2.0 * Float64(Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x)))) * sin(Float64(eps * 0.5)))); else tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - Float64(sin(x) * sin(eps))) - cos(x)); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -2.85e-5], N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.9e-5], N[(-2.0 * N[(N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $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]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.85 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 4.9 \cdot 10^{-5}:\\
\;\;\;\;-2 \cdot \left(\left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \sin x \cdot \sin \varepsilon\right) - \cos x\\
\end{array}
\end{array}
if eps < -2.8500000000000002e-5Initial program 53.6%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
associate--l+98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
fma-def98.8%
*-rgt-identity98.8%
distribute-lft-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
Simplified98.7%
if -2.8500000000000002e-5 < eps < 4.9e-5Initial program 18.6%
diff-cos35.2%
div-inv35.2%
metadata-eval35.2%
div-inv35.2%
+-commutative35.2%
metadata-eval35.2%
Applied egg-rr35.2%
*-commutative35.2%
+-commutative35.2%
associate--l+99.2%
+-inverses99.2%
distribute-lft-in99.2%
metadata-eval99.2%
*-commutative99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.7%
if 4.9e-5 < eps Initial program 53.0%
cos-sum99.1%
Applied egg-rr99.1%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.55e-5) (not (<= eps 3.1e-5))) (fma (sin x) (- (sin eps)) (* (cos x) (+ -1.0 (cos eps)))) (* -2.0 (* (+ (sin x) (* 0.5 (* eps (cos x)))) (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.55e-5) || !(eps <= 3.1e-5)) {
tmp = fma(sin(x), -sin(eps), (cos(x) * (-1.0 + cos(eps))));
} else {
tmp = -2.0 * ((sin(x) + (0.5 * (eps * cos(x)))) * sin((eps * 0.5)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -1.55e-5) || !(eps <= 3.1e-5)) tmp = fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(-1.0 + cos(eps)))); else tmp = Float64(-2.0 * Float64(Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x)))) * sin(Float64(eps * 0.5)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -1.55e-5], N[Not[LessEqual[eps, 3.1e-5]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.55 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 3.1 \cdot 10^{-5}\right):\\
\;\;\;\;\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -1.55000000000000007e-5 or 3.10000000000000014e-5 < eps Initial program 53.3%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 98.9%
neg-mul-198.9%
associate--l+98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
fma-def98.9%
*-rgt-identity98.9%
distribute-lft-out--98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
if -1.55000000000000007e-5 < eps < 3.10000000000000014e-5Initial program 18.6%
diff-cos35.2%
div-inv35.2%
metadata-eval35.2%
div-inv35.2%
+-commutative35.2%
metadata-eval35.2%
Applied egg-rr35.2%
*-commutative35.2%
+-commutative35.2%
associate--l+99.2%
+-inverses99.2%
distribute-lft-in99.2%
metadata-eval99.2%
*-commutative99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.7%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.2e-5) (not (<= eps 4.4e-5))) (- (* (cos x) (+ -1.0 (cos eps))) (* (sin x) (sin eps))) (* -2.0 (* (+ (sin x) (* 0.5 (* eps (cos x)))) (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.2e-5) || !(eps <= 4.4e-5)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(x) * sin(eps));
} else {
tmp = -2.0 * ((sin(x) + (0.5 * (eps * cos(x)))) * sin((eps * 0.5)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-4.2d-5)) .or. (.not. (eps <= 4.4d-5))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(x) * sin(eps))
else
tmp = (-2.0d0) * ((sin(x) + (0.5d0 * (eps * cos(x)))) * sin((eps * 0.5d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -4.2e-5) || !(eps <= 4.4e-5)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(x) * Math.sin(eps));
} else {
tmp = -2.0 * ((Math.sin(x) + (0.5 * (eps * Math.cos(x)))) * Math.sin((eps * 0.5)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4.2e-5) or not (eps <= 4.4e-5): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(x) * math.sin(eps)) else: tmp = -2.0 * ((math.sin(x) + (0.5 * (eps * math.cos(x)))) * math.sin((eps * 0.5))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -4.2e-5) || !(eps <= 4.4e-5)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(x) * sin(eps))); else tmp = Float64(-2.0 * Float64(Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x)))) * sin(Float64(eps * 0.5)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -4.2e-5) || ~((eps <= 4.4e-5))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(x) * sin(eps)); else tmp = -2.0 * ((sin(x) + (0.5 * (eps * cos(x)))) * sin((eps * 0.5))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.2e-5], N[Not[LessEqual[eps, 4.4e-5]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.2 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 4.4 \cdot 10^{-5}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin x \cdot \sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -4.19999999999999977e-5 or 4.3999999999999999e-5 < eps Initial program 53.3%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 98.9%
neg-mul-198.9%
associate--l+98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
fma-def98.9%
*-rgt-identity98.9%
distribute-lft-out--98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in x around inf 98.9%
neg-mul-198.9%
+-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
fma-def98.9%
fma-neg98.9%
+-commutative98.9%
*-commutative98.9%
Simplified98.9%
if -4.19999999999999977e-5 < eps < 4.3999999999999999e-5Initial program 18.6%
diff-cos35.2%
div-inv35.2%
metadata-eval35.2%
div-inv35.2%
+-commutative35.2%
metadata-eval35.2%
Applied egg-rr35.2%
*-commutative35.2%
+-commutative35.2%
associate--l+99.2%
+-inverses99.2%
distribute-lft-in99.2%
metadata-eval99.2%
*-commutative99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.7%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.019) (not (<= eps 0.0072))) (- (cos eps) (cos x)) (- (* -0.5 (* eps (* eps (cos x)))) (* (sin x) eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.019) || !(eps <= 0.0072)) {
tmp = cos(eps) - cos(x);
} else {
tmp = (-0.5 * (eps * (eps * cos(x)))) - (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 <= (-0.019d0)) .or. (.not. (eps <= 0.0072d0))) then
tmp = cos(eps) - cos(x)
else
tmp = ((-0.5d0) * (eps * (eps * cos(x)))) - (sin(x) * eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.019) || !(eps <= 0.0072)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) - (Math.sin(x) * eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.019) or not (eps <= 0.0072): tmp = math.cos(eps) - math.cos(x) else: tmp = (-0.5 * (eps * (eps * math.cos(x)))) - (math.sin(x) * eps) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.019) || !(eps <= 0.0072)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) - Float64(sin(x) * eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.019) || ~((eps <= 0.0072))) tmp = cos(eps) - cos(x); else tmp = (-0.5 * (eps * (eps * cos(x)))) - (sin(x) * eps); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.019], N[Not[LessEqual[eps, 0.0072]], $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[(N[Sin[x], $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.019 \lor \neg \left(\varepsilon \leq 0.0072\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) - \sin x \cdot \varepsilon\\
\end{array}
\end{array}
if eps < -0.0189999999999999995 or 0.0071999999999999998 < eps Initial program 53.3%
Taylor expanded in x around 0 55.1%
if -0.0189999999999999995 < eps < 0.0071999999999999998Initial program 18.9%
Taylor expanded in eps around 0 99.4%
mul-1-neg99.4%
unsub-neg99.4%
unpow299.4%
associate-*l*99.4%
Simplified99.4%
Final simplification77.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.082) (not (<= eps 0.0095))) (- (cos eps) (cos x)) (* -2.0 (* eps (* 0.5 (sin (fma eps 0.5 x)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.082) || !(eps <= 0.0095)) {
tmp = cos(eps) - cos(x);
} else {
tmp = -2.0 * (eps * (0.5 * sin(fma(eps, 0.5, x))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -0.082) || !(eps <= 0.0095)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(-2.0 * Float64(eps * Float64(0.5 * sin(fma(eps, 0.5, x))))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -0.082], N[Not[LessEqual[eps, 0.0095]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(eps * N[(0.5 * N[Sin[N[(eps * 0.5 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.082 \lor \neg \left(\varepsilon \leq 0.0095\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\varepsilon \cdot \left(0.5 \cdot \sin \left(\mathsf{fma}\left(\varepsilon, 0.5, x\right)\right)\right)\right)\\
\end{array}
\end{array}
if eps < -0.0820000000000000034 or 0.00949999999999999976 < eps Initial program 53.3%
Taylor expanded in x around 0 55.1%
if -0.0820000000000000034 < eps < 0.00949999999999999976Initial program 18.9%
diff-cos35.4%
div-inv35.4%
metadata-eval35.4%
div-inv35.4%
+-commutative35.4%
metadata-eval35.4%
Applied egg-rr35.4%
*-commutative35.4%
+-commutative35.4%
associate--l+99.2%
+-inverses99.2%
distribute-lft-in99.2%
metadata-eval99.2%
*-commutative99.2%
+-commutative99.2%
Simplified99.2%
add-sqr-sqrt44.1%
sqrt-unprod52.6%
pow252.6%
+-commutative52.6%
Applied egg-rr52.6%
unpow252.6%
rem-sqrt-square52.6%
associate-+r+52.6%
distribute-rgt-in52.6%
count-252.6%
distribute-rgt-in52.6%
+-commutative52.6%
distribute-lft-in52.6%
fma-def52.6%
associate-*r*52.6%
metadata-eval52.6%
*-lft-identity52.6%
Simplified52.6%
Taylor expanded in eps around 0 52.5%
associate-*r*52.5%
*-commutative52.5%
associate-*l*52.5%
fma-udef52.5%
*-commutative52.5%
fma-udef52.5%
rem-square-sqrt44.0%
fabs-sqr44.0%
rem-square-sqrt98.8%
Simplified98.8%
Final simplification77.1%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 (- eps (* x -2.0)))) (sin (* eps 0.5)))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * (eps - (x * -2.0)))) * sin((eps * 0.5)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((0.5d0 * (eps - (x * (-2.0d0))))) * sin((eps * 0.5d0)))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * (eps - (x * -2.0)))) * Math.sin((eps * 0.5)));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * (eps - (x * -2.0)))) * math.sin((eps * 0.5)))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))) * sin(Float64(eps * 0.5)))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * (eps - (x * -2.0)))) * sin((eps * 0.5))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * N[(eps - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 36.0%
diff-cos43.7%
div-inv43.7%
metadata-eval43.7%
div-inv43.7%
+-commutative43.7%
metadata-eval43.7%
Applied egg-rr43.7%
*-commutative43.7%
+-commutative43.7%
associate--l+77.0%
+-inverses77.0%
distribute-lft-in77.0%
metadata-eval77.0%
*-commutative77.0%
+-commutative77.0%
Simplified77.0%
Taylor expanded in x around -inf 77.0%
Final simplification77.0%
(FPCore (x eps) :precision binary64 (if (or (<= x -1.32e-30) (not (<= x 2.4e-32))) (* (sin x) (- eps)) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -1.32e-30) || !(x <= 2.4e-32)) {
tmp = sin(x) * -eps;
} 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 <= (-1.32d-30)) .or. (.not. (x <= 2.4d-32))) then
tmp = sin(x) * -eps
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 <= -1.32e-30) || !(x <= 2.4e-32)) {
tmp = Math.sin(x) * -eps;
} else {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -1.32e-30) or not (x <= 2.4e-32): tmp = math.sin(x) * -eps else: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -1.32e-30) || !(x <= 2.4e-32)) tmp = Float64(sin(x) * Float64(-eps)); 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 <= -1.32e-30) || ~((x <= 2.4e-32))) tmp = sin(x) * -eps; else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -1.32e-30], N[Not[LessEqual[x, 2.4e-32]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * (-eps)), $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 -1.32 \cdot 10^{-30} \lor \neg \left(x \leq 2.4 \cdot 10^{-32}\right):\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if x < -1.32e-30 or 2.4000000000000001e-32 < x Initial program 8.5%
Taylor expanded in eps around 0 56.0%
associate-*r*56.0%
mul-1-neg56.0%
Simplified56.0%
if -1.32e-30 < x < 2.4000000000000001e-32Initial program 73.6%
diff-cos93.6%
div-inv93.6%
metadata-eval93.6%
div-inv93.6%
+-commutative93.6%
metadata-eval93.6%
Applied egg-rr93.6%
*-commutative93.6%
+-commutative93.6%
associate--l+99.6%
+-inverses99.6%
distribute-lft-in99.6%
metadata-eval99.6%
*-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around 0 93.6%
Final simplification71.8%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000135) (not (<= eps 1.7e-7))) (- (cos eps) (cos x)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000135) || !(eps <= 1.7e-7)) {
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 <= (-0.000135d0)) .or. (.not. (eps <= 1.7d-7))) 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 <= -0.000135) || !(eps <= 1.7e-7)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000135) or not (eps <= 1.7e-7): tmp = math.cos(eps) - math.cos(x) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000135) || !(eps <= 1.7e-7)) 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 <= -0.000135) || ~((eps <= 1.7e-7))) tmp = cos(eps) - cos(x); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000135], N[Not[LessEqual[eps, 1.7e-7]], $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 -0.000135 \lor \neg \left(\varepsilon \leq 1.7 \cdot 10^{-7}\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.35000000000000002e-4 or 1.69999999999999987e-7 < eps Initial program 53.0%
Taylor expanded in x around 0 54.8%
if -1.35000000000000002e-4 < eps < 1.69999999999999987e-7Initial program 18.7%
Taylor expanded in eps around 0 83.2%
associate-*r*83.2%
mul-1-neg83.2%
Simplified83.2%
Final simplification68.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (* eps (* eps -0.5))))
(if (<= eps -0.00015)
t_0
(if (<= eps -1.35e-122)
t_1
(if (<= eps 4.9e-166) (* x (- eps)) (if (<= eps 8.2e-5) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = eps * (eps * -0.5);
double tmp;
if (eps <= -0.00015) {
tmp = t_0;
} else if (eps <= -1.35e-122) {
tmp = t_1;
} else if (eps <= 4.9e-166) {
tmp = x * -eps;
} else if (eps <= 8.2e-5) {
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 = (-1.0d0) + cos(eps)
t_1 = eps * (eps * (-0.5d0))
if (eps <= (-0.00015d0)) then
tmp = t_0
else if (eps <= (-1.35d-122)) then
tmp = t_1
else if (eps <= 4.9d-166) then
tmp = x * -eps
else if (eps <= 8.2d-5) 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 = -1.0 + Math.cos(eps);
double t_1 = eps * (eps * -0.5);
double tmp;
if (eps <= -0.00015) {
tmp = t_0;
} else if (eps <= -1.35e-122) {
tmp = t_1;
} else if (eps <= 4.9e-166) {
tmp = x * -eps;
} else if (eps <= 8.2e-5) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) t_1 = eps * (eps * -0.5) tmp = 0 if eps <= -0.00015: tmp = t_0 elif eps <= -1.35e-122: tmp = t_1 elif eps <= 4.9e-166: tmp = x * -eps elif eps <= 8.2e-5: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(eps * Float64(eps * -0.5)) tmp = 0.0 if (eps <= -0.00015) tmp = t_0; elseif (eps <= -1.35e-122) tmp = t_1; elseif (eps <= 4.9e-166) tmp = Float64(x * Float64(-eps)); elseif (eps <= 8.2e-5) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = -1.0 + cos(eps); t_1 = eps * (eps * -0.5); tmp = 0.0; if (eps <= -0.00015) tmp = t_0; elseif (eps <= -1.35e-122) tmp = t_1; elseif (eps <= 4.9e-166) tmp = x * -eps; elseif (eps <= 8.2e-5) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00015], t$95$0, If[LessEqual[eps, -1.35e-122], t$95$1, If[LessEqual[eps, 4.9e-166], N[(x * (-eps)), $MachinePrecision], If[LessEqual[eps, 8.2e-5], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := \varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\mathbf{if}\;\varepsilon \leq -0.00015:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -1.35 \cdot 10^{-122}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 4.9 \cdot 10^{-166}:\\
\;\;\;\;x \cdot \left(-\varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 8.2 \cdot 10^{-5}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.49999999999999987e-4 or 8.20000000000000009e-5 < eps Initial program 53.3%
Taylor expanded in x around 0 53.1%
if -1.49999999999999987e-4 < eps < -1.35000000000000005e-122 or 4.8999999999999999e-166 < eps < 8.20000000000000009e-5Initial program 10.7%
Taylor expanded in x around 0 10.1%
Taylor expanded in eps around 0 43.3%
*-commutative43.3%
unpow243.3%
associate-*l*43.3%
Simplified43.3%
if -1.35000000000000005e-122 < eps < 4.8999999999999999e-166Initial program 26.5%
log1p-expm1-u26.5%
Applied egg-rr26.5%
Taylor expanded in eps around 0 98.5%
mul-1-neg98.5%
*-commutative98.5%
distribute-rgt-neg-in98.5%
Simplified98.5%
Taylor expanded in x around 0 38.3%
associate-*r*38.3%
neg-mul-138.3%
Simplified38.3%
Final simplification46.8%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000135) (not (<= eps 1.7e-7))) (+ -1.0 (cos eps)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000135) || !(eps <= 1.7e-7)) {
tmp = -1.0 + cos(eps);
} 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 <= (-0.000135d0)) .or. (.not. (eps <= 1.7d-7))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.000135) || !(eps <= 1.7e-7)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000135) or not (eps <= 1.7e-7): tmp = -1.0 + math.cos(eps) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000135) || !(eps <= 1.7e-7)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000135) || ~((eps <= 1.7e-7))) tmp = -1.0 + cos(eps); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000135], N[Not[LessEqual[eps, 1.7e-7]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000135 \lor \neg \left(\varepsilon \leq 1.7 \cdot 10^{-7}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.35000000000000002e-4 or 1.69999999999999987e-7 < eps Initial program 53.0%
Taylor expanded in x around 0 52.8%
if -1.35000000000000002e-4 < eps < 1.69999999999999987e-7Initial program 18.7%
Taylor expanded in eps around 0 83.2%
associate-*r*83.2%
mul-1-neg83.2%
Simplified83.2%
Final simplification67.9%
(FPCore (x eps) :precision binary64 (* eps (* eps -0.5)))
double code(double x, double eps) {
return eps * (eps * -0.5);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * (eps * (-0.5d0))
end function
public static double code(double x, double eps) {
return eps * (eps * -0.5);
}
def code(x, eps): return eps * (eps * -0.5)
function code(x, eps) return Float64(eps * Float64(eps * -0.5)) end
function tmp = code(x, eps) tmp = eps * (eps * -0.5); end
code[x_, eps_] := N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)
\end{array}
Initial program 36.0%
Taylor expanded in x around 0 35.7%
Taylor expanded in eps around 0 19.5%
*-commutative19.5%
unpow219.5%
associate-*l*19.5%
Simplified19.5%
Final simplification19.5%
(FPCore (x eps) :precision binary64 (* x (- eps)))
double code(double x, double eps) {
return x * -eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x * -eps
end function
public static double code(double x, double eps) {
return x * -eps;
}
def code(x, eps): return x * -eps
function code(x, eps) return Float64(x * Float64(-eps)) end
function tmp = code(x, eps) tmp = x * -eps; end
code[x_, eps_] := N[(x * (-eps)), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(-\varepsilon\right)
\end{array}
Initial program 36.0%
log1p-expm1-u35.8%
Applied egg-rr35.8%
Taylor expanded in eps around 0 43.3%
mul-1-neg43.3%
*-commutative43.3%
distribute-rgt-neg-in43.3%
Simplified43.3%
Taylor expanded in x around 0 14.6%
associate-*r*14.6%
neg-mul-114.6%
Simplified14.6%
Final simplification14.6%
herbie shell --seed 2023230
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))