
(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 -0.004)
(- (fma (cos x) (cos eps) (* (sin eps) (- (sin x)))) (cos x))
(if (<= eps 0.004)
(*
(+
(* (sin x) (+ (* -0.125 (* eps eps)) 1.0))
(* (cos x) (+ (* eps 0.5) (* -0.020833333333333332 (pow eps 3.0)))))
(* -2.0 (sin (* eps 0.5))))
(- (- (* (cos x) (cos eps)) (cos x)) (* (sin eps) (sin x))))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.004) {
tmp = fma(cos(x), cos(eps), (sin(eps) * -sin(x))) - cos(x);
} else if (eps <= 0.004) {
tmp = ((sin(x) * ((-0.125 * (eps * eps)) + 1.0)) + (cos(x) * ((eps * 0.5) + (-0.020833333333333332 * pow(eps, 3.0))))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = ((cos(x) * cos(eps)) - cos(x)) - (sin(eps) * sin(x));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.004) tmp = Float64(fma(cos(x), cos(eps), Float64(sin(eps) * Float64(-sin(x)))) - cos(x)); elseif (eps <= 0.004) tmp = Float64(Float64(Float64(sin(x) * Float64(Float64(-0.125 * Float64(eps * eps)) + 1.0)) + Float64(cos(x) * Float64(Float64(eps * 0.5) + Float64(-0.020833333333333332 * (eps ^ 3.0))))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - cos(x)) - Float64(sin(eps) * sin(x))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.004], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.004], N[(N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(-0.125 * N[(eps * eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(N[(eps * 0.5), $MachinePrecision] + N[(-0.020833333333333332 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.004:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin \varepsilon \cdot \left(-\sin x\right)\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 0.004:\\
\;\;\;\;\left(\sin x \cdot \left(-0.125 \cdot \left(\varepsilon \cdot \varepsilon\right) + 1\right) + \cos x \cdot \left(\varepsilon \cdot 0.5 + -0.020833333333333332 \cdot {\varepsilon}^{3}\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \cos x\right) - \sin \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -0.0040000000000000001Initial program 46.5%
cos-sum98.5%
cancel-sign-sub-inv98.5%
fma-def98.6%
Applied egg-rr98.6%
if -0.0040000000000000001 < eps < 0.0040000000000000001Initial program 21.4%
diff-cos41.4%
div-inv41.4%
associate--l+41.4%
metadata-eval41.4%
div-inv41.4%
+-commutative41.4%
associate-+l+41.4%
metadata-eval41.4%
Applied egg-rr41.4%
associate-*r*41.4%
*-commutative41.4%
*-commutative41.4%
+-commutative41.4%
count-241.4%
fma-def41.4%
sub-neg41.4%
mul-1-neg41.4%
+-commutative41.4%
associate-+r+99.0%
mul-1-neg99.0%
sub-neg99.0%
+-inverses99.0%
remove-double-neg99.0%
mul-1-neg99.0%
sub-neg99.0%
neg-sub099.0%
mul-1-neg99.0%
remove-double-neg99.0%
Simplified99.0%
Taylor expanded in eps around 0 99.8%
associate-+r+99.8%
associate-*r*99.8%
distribute-rgt1-in99.8%
+-commutative99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
Simplified99.8%
unpow299.8%
Applied egg-rr99.8%
if 0.0040000000000000001 < eps Initial program 56.2%
sub-neg56.2%
cos-sum98.9%
associate-+l-98.8%
fma-neg98.9%
Applied egg-rr98.9%
fma-neg98.8%
*-commutative98.8%
*-commutative98.8%
fma-neg98.9%
remove-double-neg98.9%
Simplified98.9%
Taylor expanded in eps around inf 98.8%
associate--r+99.1%
*-lft-identity99.1%
distribute-rgt-out--98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
*-commutative98.9%
Simplified98.9%
distribute-lft-in99.1%
Applied egg-rr99.1%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (- (* (cos x) (/ (pow (sin eps) 2.0) (- -1.0 (cos eps)))) (* (sin eps) (sin x))))
double code(double x, double eps) {
return (cos(x) * (pow(sin(eps), 2.0) / (-1.0 - cos(eps)))) - (sin(eps) * sin(x));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (cos(x) * ((sin(eps) ** 2.0d0) / ((-1.0d0) - cos(eps)))) - (sin(eps) * sin(x))
end function
public static double code(double x, double eps) {
return (Math.cos(x) * (Math.pow(Math.sin(eps), 2.0) / (-1.0 - Math.cos(eps)))) - (Math.sin(eps) * Math.sin(x));
}
def code(x, eps): return (math.cos(x) * (math.pow(math.sin(eps), 2.0) / (-1.0 - math.cos(eps)))) - (math.sin(eps) * math.sin(x))
function code(x, eps) return Float64(Float64(cos(x) * Float64((sin(eps) ^ 2.0) / Float64(-1.0 - cos(eps)))) - Float64(sin(eps) * sin(x))) end
function tmp = code(x, eps) tmp = (cos(x) * ((sin(eps) ^ 2.0) / (-1.0 - cos(eps)))) - (sin(eps) * sin(x)); end
code[x_, eps_] := N[(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] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{{\sin \varepsilon}^{2}}{-1 - \cos \varepsilon} - \sin \varepsilon \cdot \sin x
\end{array}
Initial program 36.8%
sub-neg36.8%
cos-sum61.5%
associate-+l-61.5%
fma-neg61.5%
Applied egg-rr61.5%
fma-neg61.5%
*-commutative61.5%
*-commutative61.5%
fma-neg61.5%
remove-double-neg61.5%
Simplified61.5%
Taylor expanded in eps around inf 61.5%
associate--r+89.4%
*-lft-identity89.4%
distribute-rgt-out--89.4%
sub-neg89.4%
metadata-eval89.4%
+-commutative89.4%
*-commutative89.4%
Simplified89.4%
flip-+89.0%
metadata-eval89.0%
1-sub-cos98.9%
pow298.9%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.0039)
(fma (+ -1.0 (cos eps)) (cos x) (* (sin eps) (- (sin x))))
(if (<= eps 0.0039)
(*
(+
(* (sin x) (+ (* -0.125 (* eps eps)) 1.0))
(* (cos x) (+ (* eps 0.5) (* -0.020833333333333332 (pow eps 3.0)))))
(* -2.0 (sin (* eps 0.5))))
(- (- (* (cos x) (cos eps)) (cos x)) (* (sin eps) (sin x))))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0039) {
tmp = fma((-1.0 + cos(eps)), cos(x), (sin(eps) * -sin(x)));
} else if (eps <= 0.0039) {
tmp = ((sin(x) * ((-0.125 * (eps * eps)) + 1.0)) + (cos(x) * ((eps * 0.5) + (-0.020833333333333332 * pow(eps, 3.0))))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = ((cos(x) * cos(eps)) - cos(x)) - (sin(eps) * sin(x));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.0039) tmp = fma(Float64(-1.0 + cos(eps)), cos(x), Float64(sin(eps) * Float64(-sin(x)))); elseif (eps <= 0.0039) tmp = Float64(Float64(Float64(sin(x) * Float64(Float64(-0.125 * Float64(eps * eps)) + 1.0)) + Float64(cos(x) * Float64(Float64(eps * 0.5) + Float64(-0.020833333333333332 * (eps ^ 3.0))))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - cos(x)) - Float64(sin(eps) * sin(x))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.0039], N[(N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.0039], N[(N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(-0.125 * N[(eps * eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(N[(eps * 0.5), $MachinePrecision] + N[(-0.020833333333333332 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0039:\\
\;\;\;\;\mathsf{fma}\left(-1 + \cos \varepsilon, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.0039:\\
\;\;\;\;\left(\sin x \cdot \left(-0.125 \cdot \left(\varepsilon \cdot \varepsilon\right) + 1\right) + \cos x \cdot \left(\varepsilon \cdot 0.5 + -0.020833333333333332 \cdot {\varepsilon}^{3}\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \cos x\right) - \sin \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -0.0038999999999999998Initial program 46.5%
sub-neg46.5%
cos-sum98.5%
associate-+l-98.4%
fma-neg98.4%
Applied egg-rr98.4%
fma-neg98.4%
*-commutative98.4%
*-commutative98.4%
fma-neg98.5%
remove-double-neg98.5%
Simplified98.5%
Taylor expanded in eps around inf 98.4%
associate--r+98.4%
*-lft-identity98.4%
distribute-rgt-out--98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
*-commutative98.5%
Simplified98.5%
cancel-sign-sub-inv98.5%
*-commutative98.5%
fma-def98.5%
Applied egg-rr98.5%
if -0.0038999999999999998 < eps < 0.0038999999999999998Initial program 21.4%
diff-cos41.4%
div-inv41.4%
associate--l+41.4%
metadata-eval41.4%
div-inv41.4%
+-commutative41.4%
associate-+l+41.4%
metadata-eval41.4%
Applied egg-rr41.4%
associate-*r*41.4%
*-commutative41.4%
*-commutative41.4%
+-commutative41.4%
count-241.4%
fma-def41.4%
sub-neg41.4%
mul-1-neg41.4%
+-commutative41.4%
associate-+r+99.0%
mul-1-neg99.0%
sub-neg99.0%
+-inverses99.0%
remove-double-neg99.0%
mul-1-neg99.0%
sub-neg99.0%
neg-sub099.0%
mul-1-neg99.0%
remove-double-neg99.0%
Simplified99.0%
Taylor expanded in eps around 0 99.8%
associate-+r+99.8%
associate-*r*99.8%
distribute-rgt1-in99.8%
+-commutative99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
Simplified99.8%
unpow299.8%
Applied egg-rr99.8%
if 0.0038999999999999998 < eps Initial program 56.2%
sub-neg56.2%
cos-sum98.9%
associate-+l-98.8%
fma-neg98.9%
Applied egg-rr98.9%
fma-neg98.8%
*-commutative98.8%
*-commutative98.8%
fma-neg98.9%
remove-double-neg98.9%
Simplified98.9%
Taylor expanded in eps around inf 98.8%
associate--r+99.1%
*-lft-identity99.1%
distribute-rgt-out--98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
*-commutative98.9%
Simplified98.9%
distribute-lft-in99.1%
Applied egg-rr99.1%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.0035) (not (<= eps 0.0039)))
(fma (+ -1.0 (cos eps)) (cos x) (* (sin eps) (- (sin x))))
(*
(+
(* (sin x) (+ (* -0.125 (* eps eps)) 1.0))
(* (cos x) (+ (* eps 0.5) (* -0.020833333333333332 (pow eps 3.0)))))
(* -2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0035) || !(eps <= 0.0039)) {
tmp = fma((-1.0 + cos(eps)), cos(x), (sin(eps) * -sin(x)));
} else {
tmp = ((sin(x) * ((-0.125 * (eps * eps)) + 1.0)) + (cos(x) * ((eps * 0.5) + (-0.020833333333333332 * pow(eps, 3.0))))) * (-2.0 * sin((eps * 0.5)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -0.0035) || !(eps <= 0.0039)) tmp = fma(Float64(-1.0 + cos(eps)), cos(x), Float64(sin(eps) * Float64(-sin(x)))); else tmp = Float64(Float64(Float64(sin(x) * Float64(Float64(-0.125 * Float64(eps * eps)) + 1.0)) + Float64(cos(x) * Float64(Float64(eps * 0.5) + Float64(-0.020833333333333332 * (eps ^ 3.0))))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0035], N[Not[LessEqual[eps, 0.0039]], $MachinePrecision]], N[(N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(-0.125 * N[(eps * eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(N[(eps * 0.5), $MachinePrecision] + N[(-0.020833333333333332 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $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 -0.0035 \lor \neg \left(\varepsilon \leq 0.0039\right):\\
\;\;\;\;\mathsf{fma}\left(-1 + \cos \varepsilon, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\sin x \cdot \left(-0.125 \cdot \left(\varepsilon \cdot \varepsilon\right) + 1\right) + \cos x \cdot \left(\varepsilon \cdot 0.5 + -0.020833333333333332 \cdot {\varepsilon}^{3}\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -0.00350000000000000007 or 0.0038999999999999998 < eps Initial program 51.4%
sub-neg51.4%
cos-sum98.7%
associate-+l-98.6%
fma-neg98.7%
Applied egg-rr98.7%
fma-neg98.6%
*-commutative98.6%
*-commutative98.6%
fma-neg98.7%
remove-double-neg98.7%
Simplified98.7%
Taylor expanded in eps around inf 98.6%
associate--r+98.8%
*-lft-identity98.8%
distribute-rgt-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
Simplified98.7%
cancel-sign-sub-inv98.7%
*-commutative98.7%
fma-def98.8%
Applied egg-rr98.8%
if -0.00350000000000000007 < eps < 0.0038999999999999998Initial program 21.4%
diff-cos41.4%
div-inv41.4%
associate--l+41.4%
metadata-eval41.4%
div-inv41.4%
+-commutative41.4%
associate-+l+41.4%
metadata-eval41.4%
Applied egg-rr41.4%
associate-*r*41.4%
*-commutative41.4%
*-commutative41.4%
+-commutative41.4%
count-241.4%
fma-def41.4%
sub-neg41.4%
mul-1-neg41.4%
+-commutative41.4%
associate-+r+99.0%
mul-1-neg99.0%
sub-neg99.0%
+-inverses99.0%
remove-double-neg99.0%
mul-1-neg99.0%
sub-neg99.0%
neg-sub099.0%
mul-1-neg99.0%
remove-double-neg99.0%
Simplified99.0%
Taylor expanded in eps around 0 99.8%
associate-+r+99.8%
associate-*r*99.8%
distribute-rgt1-in99.8%
+-commutative99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
Simplified99.8%
unpow299.8%
Applied egg-rr99.8%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.0035) (not (<= eps 0.0035)))
(- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x)))
(*
(+
(* (sin x) (+ (* -0.125 (* eps eps)) 1.0))
(* (cos x) (+ (* eps 0.5) (* -0.020833333333333332 (pow eps 3.0)))))
(* -2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0035) || !(eps <= 0.0035)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = ((sin(x) * ((-0.125 * (eps * eps)) + 1.0)) + (cos(x) * ((eps * 0.5) + (-0.020833333333333332 * pow(eps, 3.0))))) * (-2.0 * 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 <= (-0.0035d0)) .or. (.not. (eps <= 0.0035d0))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = ((sin(x) * (((-0.125d0) * (eps * eps)) + 1.0d0)) + (cos(x) * ((eps * 0.5d0) + ((-0.020833333333333332d0) * (eps ** 3.0d0))))) * ((-2.0d0) * sin((eps * 0.5d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0035) || !(eps <= 0.0035)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = ((Math.sin(x) * ((-0.125 * (eps * eps)) + 1.0)) + (Math.cos(x) * ((eps * 0.5) + (-0.020833333333333332 * Math.pow(eps, 3.0))))) * (-2.0 * Math.sin((eps * 0.5)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0035) or not (eps <= 0.0035): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = ((math.sin(x) * ((-0.125 * (eps * eps)) + 1.0)) + (math.cos(x) * ((eps * 0.5) + (-0.020833333333333332 * math.pow(eps, 3.0))))) * (-2.0 * math.sin((eps * 0.5))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0035) || !(eps <= 0.0035)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(Float64(sin(x) * Float64(Float64(-0.125 * Float64(eps * eps)) + 1.0)) + Float64(cos(x) * Float64(Float64(eps * 0.5) + Float64(-0.020833333333333332 * (eps ^ 3.0))))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0035) || ~((eps <= 0.0035))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = ((sin(x) * ((-0.125 * (eps * eps)) + 1.0)) + (cos(x) * ((eps * 0.5) + (-0.020833333333333332 * (eps ^ 3.0))))) * (-2.0 * sin((eps * 0.5))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0035], N[Not[LessEqual[eps, 0.0035]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(-0.125 * N[(eps * eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(N[(eps * 0.5), $MachinePrecision] + N[(-0.020833333333333332 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $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 -0.0035 \lor \neg \left(\varepsilon \leq 0.0035\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(\sin x \cdot \left(-0.125 \cdot \left(\varepsilon \cdot \varepsilon\right) + 1\right) + \cos x \cdot \left(\varepsilon \cdot 0.5 + -0.020833333333333332 \cdot {\varepsilon}^{3}\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -0.00350000000000000007 or 0.00350000000000000007 < eps Initial program 51.4%
sub-neg51.4%
cos-sum98.7%
associate-+l-98.6%
fma-neg98.7%
Applied egg-rr98.7%
fma-neg98.6%
*-commutative98.6%
*-commutative98.6%
fma-neg98.7%
remove-double-neg98.7%
Simplified98.7%
Taylor expanded in eps around inf 98.6%
associate--r+98.8%
*-lft-identity98.8%
distribute-rgt-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
Simplified98.7%
if -0.00350000000000000007 < eps < 0.00350000000000000007Initial program 21.4%
diff-cos41.4%
div-inv41.4%
associate--l+41.4%
metadata-eval41.4%
div-inv41.4%
+-commutative41.4%
associate-+l+41.4%
metadata-eval41.4%
Applied egg-rr41.4%
associate-*r*41.4%
*-commutative41.4%
*-commutative41.4%
+-commutative41.4%
count-241.4%
fma-def41.4%
sub-neg41.4%
mul-1-neg41.4%
+-commutative41.4%
associate-+r+99.0%
mul-1-neg99.0%
sub-neg99.0%
+-inverses99.0%
remove-double-neg99.0%
mul-1-neg99.0%
sub-neg99.0%
neg-sub099.0%
mul-1-neg99.0%
remove-double-neg99.0%
Simplified99.0%
Taylor expanded in eps around 0 99.8%
associate-+r+99.8%
associate-*r*99.8%
distribute-rgt1-in99.8%
+-commutative99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
Simplified99.8%
unpow299.8%
Applied egg-rr99.8%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (or (<= x -3.4) (not (<= x 1.3e-28))) (- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x))) (* (* -2.0 (sin (/ eps 2.0))) (sin (/ (+ eps (* x 2.0)) 2.0)))))
double code(double x, double eps) {
double tmp;
if ((x <= -3.4) || !(x <= 1.3e-28)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = (-2.0 * sin((eps / 2.0))) * sin(((eps + (x * 2.0)) / 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 <= (-3.4d0)) .or. (.not. (x <= 1.3d-28))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = ((-2.0d0) * sin((eps / 2.0d0))) * sin(((eps + (x * 2.0d0)) / 2.0d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -3.4) || !(x <= 1.3e-28)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = (-2.0 * Math.sin((eps / 2.0))) * Math.sin(((eps + (x * 2.0)) / 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -3.4) or not (x <= 1.3e-28): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = (-2.0 * math.sin((eps / 2.0))) * math.sin(((eps + (x * 2.0)) / 2.0)) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -3.4) || !(x <= 1.3e-28)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(-2.0 * sin(Float64(eps / 2.0))) * sin(Float64(Float64(eps + Float64(x * 2.0)) / 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -3.4) || ~((x <= 1.3e-28))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = (-2.0 * sin((eps / 2.0))) * sin(((eps + (x * 2.0)) / 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -3.4], N[Not[LessEqual[x, 1.3e-28]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * N[Sin[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(N[(eps + N[(x * 2.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \lor \neg \left(x \leq 1.3 \cdot 10^{-28}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \sin \left(\frac{\varepsilon}{2}\right)\right) \cdot \sin \left(\frac{\varepsilon + x \cdot 2}{2}\right)\\
\end{array}
\end{array}
if x < -3.39999999999999991 or 1.3e-28 < x Initial program 8.8%
sub-neg8.8%
cos-sum56.8%
associate-+l-56.7%
fma-neg56.8%
Applied egg-rr56.8%
fma-neg56.7%
*-commutative56.7%
*-commutative56.7%
fma-neg56.8%
remove-double-neg56.8%
Simplified56.8%
Taylor expanded in eps around inf 56.7%
associate--r+98.7%
*-lft-identity98.7%
distribute-rgt-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
Simplified98.7%
if -3.39999999999999991 < x < 1.3e-28Initial program 66.5%
add-log-exp66.4%
Applied egg-rr66.4%
diff-cos66.4%
add-log-exp87.0%
+-commutative87.0%
+-commutative87.0%
Applied egg-rr87.0%
associate-*r*87.0%
associate--l+99.6%
+-inverses99.6%
associate-+l+99.6%
count-299.6%
Simplified99.6%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* eps 0.5)) (sin (* 0.5 (+ eps (+ x x)))))))
double code(double x, double eps) {
return -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps + (x + x)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((eps * 0.5d0)) * sin((0.5d0 * (eps + (x + x)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((eps * 0.5)) * Math.sin((0.5 * (eps + (x + x)))));
}
def code(x, eps): return -2.0 * (math.sin((eps * 0.5)) * math.sin((0.5 * (eps + (x + x)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(eps * 0.5)) * sin(Float64(0.5 * Float64(eps + Float64(x + x)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps + (x + x))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)\right)
\end{array}
Initial program 36.8%
diff-cos46.3%
*-commutative46.3%
div-inv46.3%
associate--l+46.3%
metadata-eval46.3%
div-inv46.3%
+-commutative46.3%
associate-+l+46.5%
metadata-eval46.5%
Applied egg-rr46.5%
Taylor expanded in x around 0 75.9%
Final simplification75.9%
(FPCore (x eps) :precision binary64 (* (* -2.0 (sin (/ eps 2.0))) (sin (/ (+ eps (* x 2.0)) 2.0))))
double code(double x, double eps) {
return (-2.0 * sin((eps / 2.0))) * sin(((eps + (x * 2.0)) / 2.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((-2.0d0) * sin((eps / 2.0d0))) * sin(((eps + (x * 2.0d0)) / 2.0d0))
end function
public static double code(double x, double eps) {
return (-2.0 * Math.sin((eps / 2.0))) * Math.sin(((eps + (x * 2.0)) / 2.0));
}
def code(x, eps): return (-2.0 * math.sin((eps / 2.0))) * math.sin(((eps + (x * 2.0)) / 2.0))
function code(x, eps) return Float64(Float64(-2.0 * sin(Float64(eps / 2.0))) * sin(Float64(Float64(eps + Float64(x * 2.0)) / 2.0))) end
function tmp = code(x, eps) tmp = (-2.0 * sin((eps / 2.0))) * sin(((eps + (x * 2.0)) / 2.0)); end
code[x_, eps_] := N[(N[(-2.0 * N[Sin[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(N[(eps + N[(x * 2.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-2 \cdot \sin \left(\frac{\varepsilon}{2}\right)\right) \cdot \sin \left(\frac{\varepsilon + x \cdot 2}{2}\right)
\end{array}
Initial program 36.8%
add-log-exp36.7%
Applied egg-rr36.7%
diff-cos36.3%
add-log-exp46.3%
+-commutative46.3%
+-commutative46.3%
Applied egg-rr46.3%
associate-*r*46.3%
associate--l+75.8%
+-inverses75.8%
associate-+l+75.9%
count-275.9%
Simplified75.9%
Final simplification75.9%
(FPCore (x eps) :precision binary64 (if (or (<= eps -6.2e-58) (not (<= eps 1.7e-23))) (* -2.0 (pow (sin (* eps 0.5)) 2.0)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -6.2e-58) || !(eps <= 1.7e-23)) {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
} else {
tmp = 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 <= (-6.2d-58)) .or. (.not. (eps <= 1.7d-23))) then
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -6.2e-58) || !(eps <= 1.7e-23)) {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -6.2e-58) or not (eps <= 1.7e-23): tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -6.2e-58) || !(eps <= 1.7e-23)) tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -6.2e-58) || ~((eps <= 1.7e-23))) tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -6.2e-58], N[Not[LessEqual[eps, 1.7e-23]], $MachinePrecision]], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -6.2 \cdot 10^{-58} \lor \neg \left(\varepsilon \leq 1.7 \cdot 10^{-23}\right):\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -6.1999999999999998e-58 or 1.7e-23 < eps Initial program 46.4%
diff-cos54.9%
div-inv54.9%
associate--l+54.9%
metadata-eval54.9%
div-inv54.9%
+-commutative54.9%
associate-+l+55.3%
metadata-eval55.3%
Applied egg-rr55.3%
associate-*r*55.3%
*-commutative55.3%
*-commutative55.3%
+-commutative55.3%
count-255.3%
fma-def55.3%
sub-neg55.3%
mul-1-neg55.3%
+-commutative55.3%
associate-+r+58.7%
mul-1-neg58.7%
sub-neg58.7%
+-inverses58.7%
remove-double-neg58.7%
mul-1-neg58.7%
sub-neg58.7%
neg-sub058.7%
mul-1-neg58.7%
remove-double-neg58.7%
Simplified58.7%
Taylor expanded in x around 0 57.1%
if -6.1999999999999998e-58 < eps < 1.7e-23Initial program 23.4%
Taylor expanded in eps around 0 89.1%
mul-1-neg89.1%
*-commutative89.1%
distribute-rgt-neg-in89.1%
Simplified89.1%
Final simplification70.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (cos eps) (cos x))))
(if (<= eps -12.2)
t_0
(if (<= eps -6.2e-58)
(* -0.5 (pow eps 2.0))
(if (<= eps 1.65e-7) (* eps (- (sin x))) t_0)))))
double code(double x, double eps) {
double t_0 = cos(eps) - cos(x);
double tmp;
if (eps <= -12.2) {
tmp = t_0;
} else if (eps <= -6.2e-58) {
tmp = -0.5 * pow(eps, 2.0);
} else if (eps <= 1.65e-7) {
tmp = eps * -sin(x);
} 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 <= (-12.2d0)) then
tmp = t_0
else if (eps <= (-6.2d-58)) then
tmp = (-0.5d0) * (eps ** 2.0d0)
else if (eps <= 1.65d-7) then
tmp = eps * -sin(x)
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 <= -12.2) {
tmp = t_0;
} else if (eps <= -6.2e-58) {
tmp = -0.5 * Math.pow(eps, 2.0);
} else if (eps <= 1.65e-7) {
tmp = eps * -Math.sin(x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) - math.cos(x) tmp = 0 if eps <= -12.2: tmp = t_0 elif eps <= -6.2e-58: tmp = -0.5 * math.pow(eps, 2.0) elif eps <= 1.65e-7: tmp = eps * -math.sin(x) else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) - cos(x)) tmp = 0.0 if (eps <= -12.2) tmp = t_0; elseif (eps <= -6.2e-58) tmp = Float64(-0.5 * (eps ^ 2.0)); elseif (eps <= 1.65e-7) tmp = Float64(eps * Float64(-sin(x))); 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 <= -12.2) tmp = t_0; elseif (eps <= -6.2e-58) tmp = -0.5 * (eps ^ 2.0); elseif (eps <= 1.65e-7) tmp = eps * -sin(x); 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, -12.2], t$95$0, If[LessEqual[eps, -6.2e-58], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 1.65e-7], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon - \cos x\\
\mathbf{if}\;\varepsilon \leq -12.2:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -6.2 \cdot 10^{-58}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\mathbf{elif}\;\varepsilon \leq 1.65 \cdot 10^{-7}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -12.199999999999999 or 1.6500000000000001e-7 < eps Initial program 51.6%
Taylor expanded in x around 0 55.1%
if -12.199999999999999 < eps < -6.1999999999999998e-58Initial program 6.5%
Taylor expanded in x around 0 8.1%
Taylor expanded in eps around 0 70.3%
if -6.1999999999999998e-58 < eps < 1.6500000000000001e-7Initial program 22.8%
Taylor expanded in eps around 0 86.8%
mul-1-neg86.8%
*-commutative86.8%
distribute-rgt-neg-in86.8%
Simplified86.8%
Final simplification69.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))))
(if (<= eps -1.18e-5)
t_0
(if (<= eps -1.15e-58)
(* -0.5 (pow eps 2.0))
(if (<= eps 2.9e-7) (* eps (- (sin x))) t_0)))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double tmp;
if (eps <= -1.18e-5) {
tmp = t_0;
} else if (eps <= -1.15e-58) {
tmp = -0.5 * pow(eps, 2.0);
} else if (eps <= 2.9e-7) {
tmp = eps * -sin(x);
} 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 = (-1.0d0) + cos(eps)
if (eps <= (-1.18d-5)) then
tmp = t_0
else if (eps <= (-1.15d-58)) then
tmp = (-0.5d0) * (eps ** 2.0d0)
else if (eps <= 2.9d-7) then
tmp = eps * -sin(x)
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 tmp;
if (eps <= -1.18e-5) {
tmp = t_0;
} else if (eps <= -1.15e-58) {
tmp = -0.5 * Math.pow(eps, 2.0);
} else if (eps <= 2.9e-7) {
tmp = eps * -Math.sin(x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) tmp = 0 if eps <= -1.18e-5: tmp = t_0 elif eps <= -1.15e-58: tmp = -0.5 * math.pow(eps, 2.0) elif eps <= 2.9e-7: tmp = eps * -math.sin(x) else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) tmp = 0.0 if (eps <= -1.18e-5) tmp = t_0; elseif (eps <= -1.15e-58) tmp = Float64(-0.5 * (eps ^ 2.0)); elseif (eps <= 2.9e-7) tmp = Float64(eps * Float64(-sin(x))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = -1.0 + cos(eps); tmp = 0.0; if (eps <= -1.18e-5) tmp = t_0; elseif (eps <= -1.15e-58) tmp = -0.5 * (eps ^ 2.0); elseif (eps <= 2.9e-7) tmp = eps * -sin(x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -1.18e-5], t$95$0, If[LessEqual[eps, -1.15e-58], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.9e-7], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
\mathbf{if}\;\varepsilon \leq -1.18 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -1.15 \cdot 10^{-58}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-7}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.18000000000000005e-5 or 2.8999999999999998e-7 < eps Initial program 50.9%
Taylor expanded in x around 0 52.8%
if -1.18000000000000005e-5 < eps < -1.1499999999999999e-58Initial program 7.1%
Taylor expanded in x around 0 7.1%
Taylor expanded in eps around 0 79.9%
if -1.1499999999999999e-58 < eps < 2.8999999999999998e-7Initial program 22.8%
Taylor expanded in eps around 0 86.8%
mul-1-neg86.8%
*-commutative86.8%
distribute-rgt-neg-in86.8%
Simplified86.8%
Final simplification68.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.18e-5) (not (<= eps 0.00015))) (+ -1.0 (cos eps)) (* -0.5 (pow eps 2.0))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.18e-5) || !(eps <= 0.00015)) {
tmp = -1.0 + cos(eps);
} else {
tmp = -0.5 * pow(eps, 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.18d-5)) .or. (.not. (eps <= 0.00015d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = (-0.5d0) * (eps ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.18e-5) || !(eps <= 0.00015)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = -0.5 * Math.pow(eps, 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.18e-5) or not (eps <= 0.00015): tmp = -1.0 + math.cos(eps) else: tmp = -0.5 * math.pow(eps, 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.18e-5) || !(eps <= 0.00015)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(-0.5 * (eps ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.18e-5) || ~((eps <= 0.00015))) tmp = -1.0 + cos(eps); else tmp = -0.5 * (eps ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.18e-5], N[Not[LessEqual[eps, 0.00015]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.18 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 0.00015\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\end{array}
\end{array}
if eps < -1.18000000000000005e-5 or 1.49999999999999987e-4 < eps Initial program 51.0%
Taylor expanded in x around 0 53.0%
if -1.18000000000000005e-5 < eps < 1.49999999999999987e-4Initial program 21.6%
Taylor expanded in x around 0 21.6%
Taylor expanded in eps around 0 40.9%
Final simplification47.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.9) (not (<= eps 1.65))) (- -1.0 (cos x)) (* (* eps eps) -0.5)))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.9) || !(eps <= 1.65)) {
tmp = -1.0 - cos(x);
} else {
tmp = (eps * 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 <= (-1.9d0)) .or. (.not. (eps <= 1.65d0))) then
tmp = (-1.0d0) - cos(x)
else
tmp = (eps * eps) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.9) || !(eps <= 1.65)) {
tmp = -1.0 - Math.cos(x);
} else {
tmp = (eps * eps) * -0.5;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.9) or not (eps <= 1.65): tmp = -1.0 - math.cos(x) else: tmp = (eps * eps) * -0.5 return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.9) || !(eps <= 1.65)) tmp = Float64(-1.0 - cos(x)); else tmp = Float64(Float64(eps * eps) * -0.5); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.9) || ~((eps <= 1.65))) tmp = -1.0 - cos(x); else tmp = (eps * eps) * -0.5; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.9], N[Not[LessEqual[eps, 1.65]], $MachinePrecision]], N[(-1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.9 \lor \neg \left(\varepsilon \leq 1.65\right):\\
\;\;\;\;-1 - \cos x\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\end{array}
\end{array}
if eps < -1.8999999999999999 or 1.6499999999999999 < eps Initial program 51.8%
add-cube-cbrt51.8%
pow351.8%
Applied egg-rr51.8%
Taylor expanded in x around 0 25.5%
unpow1/354.6%
Simplified54.6%
Taylor expanded in eps around 0 6.7%
Simplified15.9%
if -1.8999999999999999 < eps < 1.6499999999999999Initial program 21.3%
Taylor expanded in x around 0 21.4%
Taylor expanded in eps around 0 40.4%
unpow299.4%
Applied egg-rr40.4%
Final simplification28.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.18e-5) (not (<= eps 0.00015))) (+ -1.0 (cos eps)) (* (* eps eps) -0.5)))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.18e-5) || !(eps <= 0.00015)) {
tmp = -1.0 + cos(eps);
} else {
tmp = (eps * 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 <= (-1.18d-5)) .or. (.not. (eps <= 0.00015d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = (eps * eps) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.18e-5) || !(eps <= 0.00015)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = (eps * eps) * -0.5;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.18e-5) or not (eps <= 0.00015): tmp = -1.0 + math.cos(eps) else: tmp = (eps * eps) * -0.5 return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.18e-5) || !(eps <= 0.00015)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(Float64(eps * eps) * -0.5); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.18e-5) || ~((eps <= 0.00015))) tmp = -1.0 + cos(eps); else tmp = (eps * eps) * -0.5; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.18e-5], N[Not[LessEqual[eps, 0.00015]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.18 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 0.00015\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\end{array}
\end{array}
if eps < -1.18000000000000005e-5 or 1.49999999999999987e-4 < eps Initial program 51.0%
Taylor expanded in x around 0 53.0%
if -1.18000000000000005e-5 < eps < 1.49999999999999987e-4Initial program 21.6%
Taylor expanded in x around 0 21.6%
Taylor expanded in eps around 0 40.9%
unpow299.8%
Applied egg-rr40.9%
Final simplification47.2%
(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(Float64(eps * eps) * -0.5) end
function tmp = code(x, eps) tmp = (eps * eps) * -0.5; end
code[x_, eps_] := N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5
\end{array}
Initial program 36.8%
Taylor expanded in x around 0 37.8%
Taylor expanded in eps around 0 21.6%
unpow249.9%
Applied egg-rr21.6%
Final simplification21.6%
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
return 0.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
public static double code(double x, double eps) {
return 0.0;
}
def code(x, eps): return 0.0
function code(x, eps) return 0.0 end
function tmp = code(x, eps) tmp = 0.0; end
code[x_, eps_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 36.8%
add-cube-cbrt36.5%
pow336.6%
Applied egg-rr36.6%
Taylor expanded in eps around 0 11.6%
pow-base-111.6%
*-lft-identity11.6%
+-inverses11.6%
Simplified11.6%
Final simplification11.6%
herbie shell --seed 2023311
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))