
(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 15 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 (fma (sin x) (- (sin eps)) (* (cos x) (* (/ (sin eps) -1.0) (tan (/ eps 2.0))))))
double code(double x, double eps) {
return fma(sin(x), -sin(eps), (cos(x) * ((sin(eps) / -1.0) * tan((eps / 2.0)))));
}
function code(x, eps) return fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(Float64(sin(eps) / -1.0) * tan(Float64(eps / 2.0))))) end
code[x_, eps_] := N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(N[(N[Sin[eps], $MachinePrecision] / -1.0), $MachinePrecision] * N[Tan[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \left(\frac{\sin \varepsilon}{-1} \cdot \tan \left(\frac{\varepsilon}{2}\right)\right)\right)
\end{array}
Initial program 33.0%
cos-sum60.6%
cancel-sign-sub-inv60.6%
fma-def60.6%
Applied egg-rr60.6%
Taylor expanded in x around inf 60.6%
neg-mul-160.6%
distribute-lft-neg-in60.6%
associate--l+87.7%
distribute-lft-neg-in87.7%
distribute-rgt-neg-in87.7%
*-commutative87.7%
fma-def87.7%
*-rgt-identity87.7%
distribute-lft-out--87.7%
sub-neg87.7%
metadata-eval87.7%
+-commutative87.7%
Simplified87.7%
flip-+87.4%
metadata-eval87.4%
Applied egg-rr87.4%
1-sub-cos99.2%
Simplified99.2%
Taylor expanded in eps around inf 99.2%
metadata-eval99.2%
times-frac99.2%
*-lft-identity99.2%
unpow299.2%
times-frac99.2%
hang-0p-tan99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (- (* (/ (cos x) (- -1.0 (cos eps))) (pow (sin eps) 2.0)) (* (sin x) (sin eps))))
double code(double x, double eps) {
return ((cos(x) / (-1.0 - cos(eps))) * pow(sin(eps), 2.0)) - (sin(x) * sin(eps));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((cos(x) / ((-1.0d0) - cos(eps))) * (sin(eps) ** 2.0d0)) - (sin(x) * sin(eps))
end function
public static double code(double x, double eps) {
return ((Math.cos(x) / (-1.0 - Math.cos(eps))) * Math.pow(Math.sin(eps), 2.0)) - (Math.sin(x) * Math.sin(eps));
}
def code(x, eps): return ((math.cos(x) / (-1.0 - math.cos(eps))) * math.pow(math.sin(eps), 2.0)) - (math.sin(x) * math.sin(eps))
function code(x, eps) return Float64(Float64(Float64(cos(x) / Float64(-1.0 - cos(eps))) * (sin(eps) ^ 2.0)) - Float64(sin(x) * sin(eps))) end
function tmp = code(x, eps) tmp = ((cos(x) / (-1.0 - cos(eps))) * (sin(eps) ^ 2.0)) - (sin(x) * sin(eps)); end
code[x_, eps_] := N[(N[(N[(N[Cos[x], $MachinePrecision] / N[(-1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos x}{-1 - \cos \varepsilon} \cdot {\sin \varepsilon}^{2} - \sin x \cdot \sin \varepsilon
\end{array}
Initial program 33.0%
cos-sum60.6%
cancel-sign-sub-inv60.6%
fma-def60.6%
Applied egg-rr60.6%
Taylor expanded in x around inf 60.6%
neg-mul-160.6%
distribute-lft-neg-in60.6%
associate--l+87.7%
distribute-lft-neg-in87.7%
distribute-rgt-neg-in87.7%
*-commutative87.7%
fma-def87.7%
*-rgt-identity87.7%
distribute-lft-out--87.7%
sub-neg87.7%
metadata-eval87.7%
+-commutative87.7%
Simplified87.7%
flip-+87.4%
metadata-eval87.4%
Applied egg-rr87.4%
1-sub-cos99.2%
Simplified99.2%
fma-udef99.2%
associate-*r/99.2%
pow299.2%
Applied egg-rr99.2%
+-commutative99.2%
distribute-rgt-neg-out99.2%
unsub-neg99.2%
associate-/l*99.1%
associate-/r/99.2%
*-commutative99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(if (<= eps -4e-5)
(- (fma (sin eps) (- (sin x)) (* (cos x) (cos eps))) (cos x))
(if (<= eps 2.1e-5)
(* -2.0 (* (+ (sin x) (* 0.5 (* eps (cos x)))) (sin (* eps 0.5))))
(fma (cos x) (+ -1.0 (cos eps)) (* (sin x) (- (sin eps)))))))
double code(double x, double eps) {
double tmp;
if (eps <= -4e-5) {
tmp = fma(sin(eps), -sin(x), (cos(x) * cos(eps))) - cos(x);
} else if (eps <= 2.1e-5) {
tmp = -2.0 * ((sin(x) + (0.5 * (eps * cos(x)))) * sin((eps * 0.5)));
} else {
tmp = fma(cos(x), (-1.0 + cos(eps)), (sin(x) * -sin(eps)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -4e-5) tmp = Float64(fma(sin(eps), Float64(-sin(x)), Float64(cos(x) * cos(eps))) - cos(x)); elseif (eps <= 2.1e-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), Float64(-1.0 + cos(eps)), Float64(sin(x) * Float64(-sin(eps)))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -4e-5], N[(N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.1e-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[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\sin \varepsilon, -\sin x, \cos x \cdot \cos \varepsilon\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 2.1 \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, -1 + \cos \varepsilon, \sin x \cdot \left(-\sin \varepsilon\right)\right)\\
\end{array}
\end{array}
if eps < -4.00000000000000033e-5Initial program 48.6%
cos-sum98.8%
sub-neg98.8%
Applied egg-rr98.8%
+-commutative98.8%
distribute-lft-neg-in98.8%
*-commutative98.8%
fma-def98.9%
*-commutative98.9%
Simplified98.9%
if -4.00000000000000033e-5 < eps < 2.09999999999999988e-5Initial program 20.1%
diff-cos43.2%
div-inv43.2%
metadata-eval43.2%
div-inv43.2%
+-commutative43.2%
metadata-eval43.2%
Applied egg-rr43.2%
*-commutative43.2%
+-commutative43.2%
associate--l+98.8%
+-inverses98.8%
distribute-lft-in98.8%
metadata-eval98.8%
*-commutative98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in eps around 0 99.7%
if 2.09999999999999988e-5 < eps Initial program 42.1%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.7%
Applied egg-rr98.7%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
distribute-lft-neg-in98.7%
associate--l+98.8%
distribute-lft-neg-in98.8%
distribute-rgt-neg-in98.8%
*-commutative98.8%
fma-def98.8%
*-rgt-identity98.8%
distribute-lft-out--98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in x around inf 98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
distribute-rgt-neg-out98.9%
+-commutative98.9%
fma-def99.0%
+-commutative99.0%
distribute-rgt-neg-out99.0%
*-commutative99.0%
distribute-rgt-neg-in99.0%
Simplified99.0%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (<= eps -7.6e-5)
(fma (cos x) (cos eps) (- (- (cos x)) (* (sin x) (sin eps))))
(if (<= eps 2.8e-5)
(* -2.0 (* (+ (sin x) (* 0.5 (* eps (cos x)))) (sin (* eps 0.5))))
(fma (cos x) (+ -1.0 (cos eps)) (* (sin x) (- (sin eps)))))))
double code(double x, double eps) {
double tmp;
if (eps <= -7.6e-5) {
tmp = fma(cos(x), cos(eps), (-cos(x) - (sin(x) * sin(eps))));
} else if (eps <= 2.8e-5) {
tmp = -2.0 * ((sin(x) + (0.5 * (eps * cos(x)))) * sin((eps * 0.5)));
} else {
tmp = fma(cos(x), (-1.0 + cos(eps)), (sin(x) * -sin(eps)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -7.6e-5) tmp = fma(cos(x), cos(eps), Float64(Float64(-cos(x)) - Float64(sin(x) * sin(eps)))); elseif (eps <= 2.8e-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), Float64(-1.0 + cos(eps)), Float64(sin(x) * Float64(-sin(eps)))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -7.6e-5], 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], If[LessEqual[eps, 2.8e-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[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -7.6 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \left(-\cos x\right) - \sin x \cdot \sin \varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 2.8 \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, -1 + \cos \varepsilon, \sin x \cdot \left(-\sin \varepsilon\right)\right)\\
\end{array}
\end{array}
if eps < -7.6000000000000004e-5Initial program 48.6%
sub-neg48.6%
cos-sum98.8%
associate-+l-98.8%
fma-neg98.9%
Applied egg-rr98.9%
if -7.6000000000000004e-5 < eps < 2.79999999999999996e-5Initial program 20.1%
diff-cos43.2%
div-inv43.2%
metadata-eval43.2%
div-inv43.2%
+-commutative43.2%
metadata-eval43.2%
Applied egg-rr43.2%
*-commutative43.2%
+-commutative43.2%
associate--l+98.8%
+-inverses98.8%
distribute-lft-in98.8%
metadata-eval98.8%
*-commutative98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in eps around 0 99.7%
if 2.79999999999999996e-5 < eps Initial program 42.1%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.7%
Applied egg-rr98.7%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
distribute-lft-neg-in98.7%
associate--l+98.8%
distribute-lft-neg-in98.8%
distribute-rgt-neg-in98.8%
*-commutative98.8%
fma-def98.8%
*-rgt-identity98.8%
distribute-lft-out--98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in x around inf 98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
distribute-rgt-neg-out98.9%
+-commutative98.9%
fma-def99.0%
+-commutative99.0%
distribute-rgt-neg-out99.0%
*-commutative99.0%
distribute-rgt-neg-in99.0%
Simplified99.0%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -2.7e-5) (not (<= eps 2.7e-5))) (fma (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 <= -2.7e-5) || !(eps <= 2.7e-5)) {
tmp = fma(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;
}
function code(x, eps) tmp = 0.0 if ((eps <= -2.7e-5) || !(eps <= 2.7e-5)) tmp = fma(cos(x), Float64(-1.0 + cos(eps)), Float64(sin(x) * Float64(-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, -2.7e-5], N[Not[LessEqual[eps, 2.7e-5]], $MachinePrecision]], N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $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 -2.7 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 2.7 \cdot 10^{-5}\right):\\
\;\;\;\;\mathsf{fma}\left(\cos x, -1 + \cos \varepsilon, \sin x \cdot \left(-\sin \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 < -2.6999999999999999e-5 or 2.6999999999999999e-5 < eps Initial program 45.6%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.7%
Applied egg-rr98.7%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
distribute-lft-neg-in98.7%
associate--l+98.8%
distribute-lft-neg-in98.8%
distribute-rgt-neg-in98.8%
*-commutative98.8%
fma-def98.8%
*-rgt-identity98.8%
distribute-lft-out--98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in x around inf 98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
mul-1-neg98.8%
distribute-rgt-neg-out98.8%
+-commutative98.8%
fma-def98.9%
+-commutative98.9%
distribute-rgt-neg-out98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
Simplified98.9%
if -2.6999999999999999e-5 < eps < 2.6999999999999999e-5Initial program 20.1%
diff-cos43.2%
div-inv43.2%
metadata-eval43.2%
div-inv43.2%
+-commutative43.2%
metadata-eval43.2%
Applied egg-rr43.2%
*-commutative43.2%
+-commutative43.2%
associate--l+98.8%
+-inverses98.8%
distribute-lft-in98.8%
metadata-eval98.8%
*-commutative98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in eps around 0 99.7%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -2.05e-5) (not (<= eps 2.75e-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 <= -2.05e-5) || !(eps <= 2.75e-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 <= (-2.05d-5)) .or. (.not. (eps <= 2.75d-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 <= -2.05e-5) || !(eps <= 2.75e-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 <= -2.05e-5) or not (eps <= 2.75e-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 <= -2.05e-5) || !(eps <= 2.75e-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 <= -2.05e-5) || ~((eps <= 2.75e-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, -2.05e-5], N[Not[LessEqual[eps, 2.75e-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 -2.05 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 2.75 \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 < -2.05000000000000002e-5 or 2.7500000000000001e-5 < eps Initial program 45.6%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.7%
Applied egg-rr98.7%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
distribute-lft-neg-in98.7%
associate--l+98.8%
distribute-lft-neg-in98.8%
distribute-rgt-neg-in98.8%
*-commutative98.8%
fma-def98.8%
*-rgt-identity98.8%
distribute-lft-out--98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
Simplified98.8%
fma-udef98.8%
Applied egg-rr98.8%
if -2.05000000000000002e-5 < eps < 2.7500000000000001e-5Initial program 20.1%
diff-cos43.2%
div-inv43.2%
metadata-eval43.2%
div-inv43.2%
+-commutative43.2%
metadata-eval43.2%
Applied egg-rr43.2%
*-commutative43.2%
+-commutative43.2%
associate--l+98.8%
+-inverses98.8%
distribute-lft-in98.8%
metadata-eval98.8%
*-commutative98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in eps around 0 99.7%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ x eps)) (cos x)) -1e-12) (- (cos eps) (cos x)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((cos((x + eps)) - cos(x)) <= -1e-12) {
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 ((cos((x + eps)) - cos(x)) <= (-1d-12)) 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 ((Math.cos((x + eps)) - Math.cos(x)) <= -1e-12) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((x + eps)) - math.cos(x)) <= -1e-12: tmp = math.cos(eps) - math.cos(x) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(x + eps)) - cos(x)) <= -1e-12) 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 ((cos((x + eps)) - cos(x)) <= -1e-12) tmp = cos(eps) - cos(x); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -1e-12], 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}\;\cos \left(x + \varepsilon\right) - \cos x \leq -1 \cdot 10^{-12}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.9999999999999998e-13Initial program 72.5%
Taylor expanded in x around 0 73.0%
if -9.9999999999999998e-13 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 16.6%
Taylor expanded in eps around 0 54.6%
associate-*r*54.6%
mul-1-neg54.6%
Simplified54.6%
Final simplification60.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -200.0) (not (<= eps 165000.0))) (- (cos eps) (cos x)) (- (* -0.5 (* eps (* eps (cos x)))) (* (sin x) eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -200.0) || !(eps <= 165000.0)) {
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 <= (-200.0d0)) .or. (.not. (eps <= 165000.0d0))) 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 <= -200.0) || !(eps <= 165000.0)) {
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 <= -200.0) or not (eps <= 165000.0): 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 <= -200.0) || !(eps <= 165000.0)) 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 <= -200.0) || ~((eps <= 165000.0))) 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, -200.0], N[Not[LessEqual[eps, 165000.0]], $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 -200 \lor \neg \left(\varepsilon \leq 165000\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 < -200 or 165000 < eps Initial program 47.1%
Taylor expanded in x around 0 49.0%
if -200 < eps < 165000Initial program 19.7%
Taylor expanded in eps around 0 97.0%
mul-1-neg97.0%
unsub-neg97.0%
unpow297.0%
associate-*l*97.0%
Simplified97.0%
Final simplification73.7%
(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 33.0%
diff-cos43.3%
div-inv43.3%
metadata-eval43.3%
div-inv43.3%
+-commutative43.3%
metadata-eval43.3%
Applied egg-rr43.3%
*-commutative43.3%
+-commutative43.3%
associate--l+72.0%
+-inverses72.0%
distribute-lft-in72.0%
metadata-eval72.0%
*-commutative72.0%
+-commutative72.0%
Simplified72.0%
Taylor expanded in x around -inf 72.0%
Final simplification72.0%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 (+ x (+ x eps)))) (sin (* eps 0.5)))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * (x + (x + eps)))) * 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 * (x + (x + eps)))) * sin((eps * 0.5d0)))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * (x + (x + eps)))) * Math.sin((eps * 0.5)));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * (x + (x + eps)))) * math.sin((eps * 0.5)))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * Float64(x + Float64(x + eps)))) * sin(Float64(eps * 0.5)))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * (x + (x + eps)))) * sin((eps * 0.5))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * N[(x + N[(x + eps), $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(x + \left(x + \varepsilon\right)\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 33.0%
diff-cos43.3%
div-inv43.3%
metadata-eval43.3%
div-inv43.3%
+-commutative43.3%
metadata-eval43.3%
Applied egg-rr43.3%
*-commutative43.3%
+-commutative43.3%
associate--l+72.0%
+-inverses72.0%
distribute-lft-in72.0%
metadata-eval72.0%
*-commutative72.0%
+-commutative72.0%
Simplified72.0%
add-exp-log50.2%
*-commutative50.2%
+-commutative50.2%
+-rgt-identity50.2%
Applied egg-rr50.2%
add-exp-log72.0%
*-un-lft-identity72.0%
+-commutative72.0%
*-commutative72.0%
Applied egg-rr72.0%
*-lft-identity72.0%
*-commutative72.0%
Simplified72.0%
Final simplification72.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -2.65e-51) (not (<= x 6.2e-26)))
(* -2.0 (* (sin x) 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 <= -2.65e-51) || !(x <= 6.2e-26)) {
tmp = -2.0 * (sin(x) * 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 <= (-2.65d-51)) .or. (.not. (x <= 6.2d-26))) then
tmp = (-2.0d0) * (sin(x) * 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 <= -2.65e-51) || !(x <= 6.2e-26)) {
tmp = -2.0 * (Math.sin(x) * 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 <= -2.65e-51) or not (x <= 6.2e-26): tmp = -2.0 * (math.sin(x) * 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 <= -2.65e-51) || !(x <= 6.2e-26)) tmp = Float64(-2.0 * Float64(sin(x) * 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 <= -2.65e-51) || ~((x <= 6.2e-26))) tmp = -2.0 * (sin(x) * 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, -2.65e-51], N[Not[LessEqual[x, 6.2e-26]], $MachinePrecision]], N[(-2.0 * N[(N[Sin[x], $MachinePrecision] * 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 -2.65 \cdot 10^{-51} \lor \neg \left(x \leq 6.2 \cdot 10^{-26}\right):\\
\;\;\;\;-2 \cdot \left(\sin x \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -2.64999999999999987e-51 or 6.19999999999999966e-26 < x Initial program 12.4%
diff-cos10.7%
div-inv10.7%
metadata-eval10.7%
div-inv10.7%
+-commutative10.7%
metadata-eval10.7%
Applied egg-rr10.7%
*-commutative10.7%
+-commutative10.7%
associate--l+54.4%
+-inverses54.4%
distribute-lft-in54.4%
metadata-eval54.4%
*-commutative54.4%
+-commutative54.4%
Simplified54.4%
Taylor expanded in eps around 0 51.4%
if -2.64999999999999987e-51 < x < 6.19999999999999966e-26Initial program 65.0%
diff-cos94.3%
div-inv94.3%
metadata-eval94.3%
div-inv94.3%
+-commutative94.3%
metadata-eval94.3%
Applied egg-rr94.3%
*-commutative94.3%
+-commutative94.3%
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 92.4%
Final simplification67.4%
(FPCore (x eps) :precision binary64 (if (or (<= x -4.6e-52) (not (<= x 7.2e-27))) (* (sin x) (- eps)) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -4.6e-52) || !(x <= 7.2e-27)) {
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 <= (-4.6d-52)) .or. (.not. (x <= 7.2d-27))) 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 <= -4.6e-52) || !(x <= 7.2e-27)) {
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 <= -4.6e-52) or not (x <= 7.2e-27): 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 <= -4.6e-52) || !(x <= 7.2e-27)) 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 <= -4.6e-52) || ~((x <= 7.2e-27))) 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, -4.6e-52], N[Not[LessEqual[x, 7.2e-27]], $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 -4.6 \cdot 10^{-52} \lor \neg \left(x \leq 7.2 \cdot 10^{-27}\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 < -4.59999999999999989e-52 or 7.1999999999999997e-27 < x Initial program 12.4%
Taylor expanded in eps around 0 47.9%
associate-*r*47.9%
mul-1-neg47.9%
Simplified47.9%
if -4.59999999999999989e-52 < x < 7.1999999999999997e-27Initial program 65.0%
diff-cos94.3%
div-inv94.3%
metadata-eval94.3%
div-inv94.3%
+-commutative94.3%
metadata-eval94.3%
Applied egg-rr94.3%
*-commutative94.3%
+-commutative94.3%
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 92.4%
Final simplification65.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (* (sin x) (- eps))))
(if (<= eps -0.00285)
t_0
(if (<= eps 5.2e-111)
t_1
(if (<= eps 5.5e-36)
(* -0.5 (* eps eps))
(if (<= eps 4.8e-6) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = sin(x) * -eps;
double tmp;
if (eps <= -0.00285) {
tmp = t_0;
} else if (eps <= 5.2e-111) {
tmp = t_1;
} else if (eps <= 5.5e-36) {
tmp = -0.5 * (eps * eps);
} else if (eps <= 4.8e-6) {
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 = sin(x) * -eps
if (eps <= (-0.00285d0)) then
tmp = t_0
else if (eps <= 5.2d-111) then
tmp = t_1
else if (eps <= 5.5d-36) then
tmp = (-0.5d0) * (eps * eps)
else if (eps <= 4.8d-6) 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 = Math.sin(x) * -eps;
double tmp;
if (eps <= -0.00285) {
tmp = t_0;
} else if (eps <= 5.2e-111) {
tmp = t_1;
} else if (eps <= 5.5e-36) {
tmp = -0.5 * (eps * eps);
} else if (eps <= 4.8e-6) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) t_1 = math.sin(x) * -eps tmp = 0 if eps <= -0.00285: tmp = t_0 elif eps <= 5.2e-111: tmp = t_1 elif eps <= 5.5e-36: tmp = -0.5 * (eps * eps) elif eps <= 4.8e-6: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(sin(x) * Float64(-eps)) tmp = 0.0 if (eps <= -0.00285) tmp = t_0; elseif (eps <= 5.2e-111) tmp = t_1; elseif (eps <= 5.5e-36) tmp = Float64(-0.5 * Float64(eps * eps)); elseif (eps <= 4.8e-6) 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 = sin(x) * -eps; tmp = 0.0; if (eps <= -0.00285) tmp = t_0; elseif (eps <= 5.2e-111) tmp = t_1; elseif (eps <= 5.5e-36) tmp = -0.5 * (eps * eps); elseif (eps <= 4.8e-6) 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[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]}, If[LessEqual[eps, -0.00285], t$95$0, If[LessEqual[eps, 5.2e-111], t$95$1, If[LessEqual[eps, 5.5e-36], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.8e-6], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := \sin x \cdot \left(-\varepsilon\right)\\
\mathbf{if}\;\varepsilon \leq -0.00285:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 5.2 \cdot 10^{-111}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 5.5 \cdot 10^{-36}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 4.8 \cdot 10^{-6}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -0.0028500000000000001 or 4.7999999999999998e-6 < eps Initial program 46.3%
Taylor expanded in x around 0 46.4%
if -0.0028500000000000001 < eps < 5.19999999999999965e-111 or 5.49999999999999984e-36 < eps < 4.7999999999999998e-6Initial program 22.2%
Taylor expanded in eps around 0 81.4%
associate-*r*81.4%
mul-1-neg81.4%
Simplified81.4%
if 5.19999999999999965e-111 < eps < 5.49999999999999984e-36Initial program 4.4%
Taylor expanded in x around 0 4.4%
Taylor expanded in eps around 0 66.8%
unpow266.8%
Simplified66.8%
Final simplification63.1%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.00285) (not (<= eps 4.3e-13))) (+ -1.0 (cos eps)) (* -0.5 (* eps eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00285) || !(eps <= 4.3e-13)) {
tmp = -1.0 + cos(eps);
} 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 <= (-0.00285d0)) .or. (.not. (eps <= 4.3d-13))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = (-0.5d0) * (eps * eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.00285) || !(eps <= 4.3e-13)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00285) or not (eps <= 4.3e-13): tmp = -1.0 + math.cos(eps) else: tmp = -0.5 * (eps * eps) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00285) || !(eps <= 4.3e-13)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(-0.5 * Float64(eps * eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00285) || ~((eps <= 4.3e-13))) tmp = -1.0 + cos(eps); else tmp = -0.5 * (eps * eps); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00285], N[Not[LessEqual[eps, 4.3e-13]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00285 \lor \neg \left(\varepsilon \leq 4.3 \cdot 10^{-13}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\end{array}
\end{array}
if eps < -0.0028500000000000001 or 4.2999999999999999e-13 < eps Initial program 45.3%
Taylor expanded in x around 0 45.5%
if -0.0028500000000000001 < eps < 4.2999999999999999e-13Initial program 20.2%
Taylor expanded in x around 0 20.3%
Taylor expanded in eps around 0 42.2%
unpow242.2%
Simplified42.2%
Final simplification43.9%
(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 33.0%
Taylor expanded in x around 0 33.1%
Taylor expanded in eps around 0 22.4%
unpow222.4%
Simplified22.4%
Final simplification22.4%
herbie shell --seed 2023173
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))