
(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 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -1.45e-9) (not (<= x 1.45e-8)))
(- (- (* (cos eps) (cos x)) (cos x)) (* (sin eps) (sin x)))
(* (+ (* x (cos (* eps 0.5))) t_0) (* -2.0 t_0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -1.45e-9) || !(x <= 1.45e-8)) {
tmp = ((cos(eps) * cos(x)) - cos(x)) - (sin(eps) * sin(x));
} else {
tmp = ((x * cos((eps * 0.5))) + t_0) * (-2.0 * 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 = sin((eps * 0.5d0))
if ((x <= (-1.45d-9)) .or. (.not. (x <= 1.45d-8))) then
tmp = ((cos(eps) * cos(x)) - cos(x)) - (sin(eps) * sin(x))
else
tmp = ((x * cos((eps * 0.5d0))) + t_0) * ((-2.0d0) * t_0)
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 <= -1.45e-9) || !(x <= 1.45e-8)) {
tmp = ((Math.cos(eps) * Math.cos(x)) - Math.cos(x)) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = ((x * Math.cos((eps * 0.5))) + t_0) * (-2.0 * t_0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -1.45e-9) or not (x <= 1.45e-8): tmp = ((math.cos(eps) * math.cos(x)) - math.cos(x)) - (math.sin(eps) * math.sin(x)) else: tmp = ((x * math.cos((eps * 0.5))) + t_0) * (-2.0 * t_0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -1.45e-9) || !(x <= 1.45e-8)) tmp = Float64(Float64(Float64(cos(eps) * cos(x)) - cos(x)) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(Float64(x * cos(Float64(eps * 0.5))) + t_0) * Float64(-2.0 * t_0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -1.45e-9) || ~((x <= 1.45e-8))) tmp = ((cos(eps) * cos(x)) - cos(x)) - (sin(eps) * sin(x)); else tmp = ((x * cos((eps * 0.5))) + t_0) * (-2.0 * t_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, -1.45e-9], N[Not[LessEqual[x, 1.45e-8]], $MachinePrecision]], N[(N[(N[(N[Cos[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -1.45 \cdot 10^{-9} \lor \neg \left(x \leq 1.45 \cdot 10^{-8}\right):\\
\;\;\;\;\left(\cos \varepsilon \cdot \cos x - \cos x\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot \cos \left(\varepsilon \cdot 0.5\right) + t_0\right) \cdot \left(-2 \cdot t_0\right)\\
\end{array}
\end{array}
if x < -1.44999999999999996e-9 or 1.4500000000000001e-8 < x Initial program 7.0%
sub-neg7.0%
cos-sum55.7%
associate-+l-55.7%
fma-neg55.7%
Applied egg-rr55.7%
Taylor expanded in x around inf 55.7%
associate--r+99.2%
*-commutative99.2%
*-rgt-identity99.2%
distribute-lft-out--99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
*-commutative99.0%
Simplified99.0%
+-commutative99.0%
distribute-rgt-in99.2%
neg-mul-199.2%
Applied egg-rr99.2%
if -1.44999999999999996e-9 < x < 1.4500000000000001e-8Initial program 71.7%
diff-cos88.6%
div-inv88.6%
associate--l+88.6%
metadata-eval88.6%
div-inv88.6%
+-commutative88.6%
associate-+l+88.6%
metadata-eval88.6%
Applied egg-rr88.6%
associate-*r*88.6%
*-commutative88.6%
*-commutative88.6%
+-commutative88.6%
count-288.6%
fma-def88.6%
sub-neg88.6%
mul-1-neg88.6%
+-commutative88.6%
associate-+r+98.7%
mul-1-neg98.7%
sub-neg98.7%
+-inverses98.7%
remove-double-neg98.7%
mul-1-neg98.7%
sub-neg98.7%
neg-sub098.7%
mul-1-neg98.7%
remove-double-neg98.7%
Simplified98.7%
Taylor expanded in x around 0 99.6%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (- (/ (pow (sin eps) 2.0) (/ (- -1.0 (cos eps)) (cos x))) (* (sin eps) (sin x))))
double code(double x, double eps) {
return (pow(sin(eps), 2.0) / ((-1.0 - cos(eps)) / cos(x))) - (sin(eps) * sin(x));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((sin(eps) ** 2.0d0) / (((-1.0d0) - cos(eps)) / cos(x))) - (sin(eps) * sin(x))
end function
public static double code(double x, double eps) {
return (Math.pow(Math.sin(eps), 2.0) / ((-1.0 - Math.cos(eps)) / Math.cos(x))) - (Math.sin(eps) * Math.sin(x));
}
def code(x, eps): return (math.pow(math.sin(eps), 2.0) / ((-1.0 - math.cos(eps)) / math.cos(x))) - (math.sin(eps) * math.sin(x))
function code(x, eps) return Float64(Float64((sin(eps) ^ 2.0) / Float64(Float64(-1.0 - cos(eps)) / cos(x))) - Float64(sin(eps) * sin(x))) end
function tmp = code(x, eps) tmp = ((sin(eps) ^ 2.0) / ((-1.0 - cos(eps)) / cos(x))) - (sin(eps) * sin(x)); end
code[x_, eps_] := N[(N[(N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision] / N[(N[(-1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\sin \varepsilon}^{2}}{\frac{-1 - \cos \varepsilon}{\cos x}} - \sin \varepsilon \cdot \sin x
\end{array}
Initial program 39.9%
sub-neg39.9%
cos-sum64.3%
associate-+l-64.3%
fma-neg64.3%
Applied egg-rr64.3%
Taylor expanded in x around inf 64.3%
associate--r+91.0%
*-commutative91.0%
*-rgt-identity91.0%
distribute-lft-out--90.9%
sub-neg90.9%
metadata-eval90.9%
+-commutative90.9%
*-commutative90.9%
Simplified90.9%
flip-+90.7%
associate-*r/90.6%
metadata-eval90.6%
1-sub-cos98.9%
pow298.9%
Applied egg-rr98.9%
*-commutative98.9%
associate-/l*99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (sin (* eps 0.5))))
(if (<= x -5e-9)
(- (* (cos x) t_0) (* (sin eps) (sin x)))
(if (<= x 9.5e-9)
(* (+ (* x (cos (* eps 0.5))) t_1) (* -2.0 t_1))
(fma t_0 (cos x) (* (sin eps) (- (sin x))))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = sin((eps * 0.5));
double tmp;
if (x <= -5e-9) {
tmp = (cos(x) * t_0) - (sin(eps) * sin(x));
} else if (x <= 9.5e-9) {
tmp = ((x * cos((eps * 0.5))) + t_1) * (-2.0 * t_1);
} else {
tmp = fma(t_0, cos(x), (sin(eps) * -sin(x)));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = sin(Float64(eps * 0.5)) tmp = 0.0 if (x <= -5e-9) tmp = Float64(Float64(cos(x) * t_0) - Float64(sin(eps) * sin(x))); elseif (x <= 9.5e-9) tmp = Float64(Float64(Float64(x * cos(Float64(eps * 0.5))) + t_1) * Float64(-2.0 * t_1)); else tmp = fma(t_0, cos(x), Float64(sin(eps) * Float64(-sin(x)))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -5e-9], N[(N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9.5e-9], N[(N[(N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] * N[(-2.0 * t$95$1), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -5 \cdot 10^{-9}:\\
\;\;\;\;\cos x \cdot t_0 - \sin \varepsilon \cdot \sin x\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{-9}:\\
\;\;\;\;\left(x \cdot \cos \left(\varepsilon \cdot 0.5\right) + t_1\right) \cdot \left(-2 \cdot t_1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\end{array}
\end{array}
if x < -5.0000000000000001e-9Initial program 8.3%
sub-neg8.3%
cos-sum55.8%
associate-+l-55.8%
fma-neg55.8%
Applied egg-rr55.8%
Taylor expanded in x around inf 55.8%
associate--r+99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
*-commutative99.3%
Simplified99.3%
if -5.0000000000000001e-9 < x < 9.5000000000000007e-9Initial program 71.7%
diff-cos88.6%
div-inv88.6%
associate--l+88.6%
metadata-eval88.6%
div-inv88.6%
+-commutative88.6%
associate-+l+88.6%
metadata-eval88.6%
Applied egg-rr88.6%
associate-*r*88.6%
*-commutative88.6%
*-commutative88.6%
+-commutative88.6%
count-288.6%
fma-def88.6%
sub-neg88.6%
mul-1-neg88.6%
+-commutative88.6%
associate-+r+98.7%
mul-1-neg98.7%
sub-neg98.7%
+-inverses98.7%
remove-double-neg98.7%
mul-1-neg98.7%
sub-neg98.7%
neg-sub098.7%
mul-1-neg98.7%
remove-double-neg98.7%
Simplified98.7%
Taylor expanded in x around 0 99.6%
if 9.5000000000000007e-9 < x Initial program 5.6%
sub-neg5.6%
cos-sum55.5%
associate-+l-55.6%
fma-neg55.7%
Applied egg-rr55.7%
Taylor expanded in x around inf 55.6%
associate--r+98.9%
*-commutative98.9%
*-rgt-identity98.9%
distribute-lft-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
Simplified98.7%
+-commutative98.7%
*-commutative98.7%
fma-neg98.8%
+-commutative98.8%
distribute-rgt-neg-in98.8%
Applied egg-rr98.8%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -2.4e-8) (not (<= x 1.65e-8)))
(- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x)))
(* (+ (* x (cos (* eps 0.5))) t_0) (* -2.0 t_0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -2.4e-8) || !(x <= 1.65e-8)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = ((x * cos((eps * 0.5))) + t_0) * (-2.0 * 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 = sin((eps * 0.5d0))
if ((x <= (-2.4d-8)) .or. (.not. (x <= 1.65d-8))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = ((x * cos((eps * 0.5d0))) + t_0) * ((-2.0d0) * t_0)
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.4e-8) || !(x <= 1.65e-8)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = ((x * Math.cos((eps * 0.5))) + t_0) * (-2.0 * t_0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -2.4e-8) or not (x <= 1.65e-8): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = ((x * math.cos((eps * 0.5))) + t_0) * (-2.0 * t_0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -2.4e-8) || !(x <= 1.65e-8)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(Float64(x * cos(Float64(eps * 0.5))) + t_0) * Float64(-2.0 * t_0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -2.4e-8) || ~((x <= 1.65e-8))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = ((x * cos((eps * 0.5))) + t_0) * (-2.0 * t_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.4e-8], N[Not[LessEqual[x, 1.65e-8]], $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[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -2.4 \cdot 10^{-8} \lor \neg \left(x \leq 1.65 \cdot 10^{-8}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot \cos \left(\varepsilon \cdot 0.5\right) + t_0\right) \cdot \left(-2 \cdot t_0\right)\\
\end{array}
\end{array}
if x < -2.39999999999999998e-8 or 1.64999999999999989e-8 < x Initial program 7.0%
sub-neg7.0%
cos-sum55.7%
associate-+l-55.7%
fma-neg55.7%
Applied egg-rr55.7%
Taylor expanded in x around inf 55.7%
associate--r+99.2%
*-commutative99.2%
*-rgt-identity99.2%
distribute-lft-out--99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
*-commutative99.0%
Simplified99.0%
if -2.39999999999999998e-8 < x < 1.64999999999999989e-8Initial program 71.7%
diff-cos88.6%
div-inv88.6%
associate--l+88.6%
metadata-eval88.6%
div-inv88.6%
+-commutative88.6%
associate-+l+88.6%
metadata-eval88.6%
Applied egg-rr88.6%
associate-*r*88.6%
*-commutative88.6%
*-commutative88.6%
+-commutative88.6%
count-288.6%
fma-def88.6%
sub-neg88.6%
mul-1-neg88.6%
+-commutative88.6%
associate-+r+98.7%
mul-1-neg98.7%
sub-neg98.7%
+-inverses98.7%
remove-double-neg98.7%
mul-1-neg98.7%
sub-neg98.7%
neg-sub098.7%
mul-1-neg98.7%
remove-double-neg98.7%
Simplified98.7%
Taylor expanded in x around 0 99.6%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -1e-16) (- (cos eps) (cos x)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -1e-16) {
tmp = cos(eps) - cos(x);
} 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 ((cos((eps + x)) - cos(x)) <= (-1d-16)) then
tmp = cos(eps) - cos(x)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -1e-16) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -1e-16: tmp = math.cos(eps) - math.cos(x) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -1e-16) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -1e-16) tmp = cos(eps) - cos(x); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -1e-16], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -1 \cdot 10^{-16}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.9999999999999998e-17Initial program 79.7%
Taylor expanded in x around 0 79.9%
if -9.9999999999999998e-17 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 19.7%
Taylor expanded in eps around 0 58.8%
mul-1-neg58.8%
*-commutative58.8%
distribute-rgt-neg-in58.8%
Simplified58.8%
Final simplification65.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -7e-15) (not (<= x 1.02e-44)))
(* (sin x) (* -2.0 t_0))
(* -2.0 (pow t_0 2.0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -7e-15) || !(x <= 1.02e-44)) {
tmp = sin(x) * (-2.0 * t_0);
} else {
tmp = -2.0 * pow(t_0, 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((eps * 0.5d0))
if ((x <= (-7d-15)) .or. (.not. (x <= 1.02d-44))) then
tmp = sin(x) * ((-2.0d0) * t_0)
else
tmp = (-2.0d0) * (t_0 ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
double tmp;
if ((x <= -7e-15) || !(x <= 1.02e-44)) {
tmp = Math.sin(x) * (-2.0 * t_0);
} else {
tmp = -2.0 * Math.pow(t_0, 2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -7e-15) or not (x <= 1.02e-44): tmp = math.sin(x) * (-2.0 * t_0) else: tmp = -2.0 * math.pow(t_0, 2.0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -7e-15) || !(x <= 1.02e-44)) tmp = Float64(sin(x) * Float64(-2.0 * t_0)); else tmp = Float64(-2.0 * (t_0 ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -7e-15) || ~((x <= 1.02e-44))) tmp = sin(x) * (-2.0 * t_0); else tmp = -2.0 * (t_0 ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -7e-15], N[Not[LessEqual[x, 1.02e-44]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -7 \cdot 10^{-15} \lor \neg \left(x \leq 1.02 \cdot 10^{-44}\right):\\
\;\;\;\;\sin x \cdot \left(-2 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -7.0000000000000001e-15 or 1.0199999999999999e-44 < x Initial program 8.8%
diff-cos8.4%
div-inv8.4%
associate--l+8.4%
metadata-eval8.4%
div-inv8.4%
+-commutative8.4%
associate-+l+8.6%
metadata-eval8.6%
Applied egg-rr8.6%
associate-*r*8.6%
*-commutative8.6%
*-commutative8.6%
+-commutative8.6%
count-28.6%
fma-def8.6%
sub-neg8.6%
mul-1-neg8.6%
+-commutative8.6%
associate-+r+54.5%
mul-1-neg54.5%
sub-neg54.5%
+-inverses54.5%
remove-double-neg54.5%
mul-1-neg54.5%
sub-neg54.5%
neg-sub054.5%
mul-1-neg54.5%
remove-double-neg54.5%
Simplified54.5%
Taylor expanded in eps around 0 53.2%
if -7.0000000000000001e-15 < x < 1.0199999999999999e-44Initial program 74.5%
diff-cos92.1%
div-inv92.1%
associate--l+92.1%
metadata-eval92.1%
div-inv92.1%
+-commutative92.1%
associate-+l+92.1%
metadata-eval92.1%
Applied egg-rr92.1%
associate-*r*92.1%
*-commutative92.1%
*-commutative92.1%
+-commutative92.1%
count-292.1%
fma-def92.1%
sub-neg92.1%
mul-1-neg92.1%
+-commutative92.1%
associate-+r+99.6%
mul-1-neg99.6%
sub-neg99.6%
+-inverses99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
neg-sub099.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 91.2%
Final simplification71.2%
(FPCore (x eps) :precision binary64 (if (or (<= x -7.2e-15) (not (<= x 9.6e-45))) (* eps (- (sin x))) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -7.2e-15) || !(x <= 9.6e-45)) {
tmp = eps * -sin(x);
} else {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-7.2d-15)) .or. (.not. (x <= 9.6d-45))) then
tmp = eps * -sin(x)
else
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -7.2e-15) || !(x <= 9.6e-45)) {
tmp = eps * -Math.sin(x);
} else {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -7.2e-15) or not (x <= 9.6e-45): tmp = eps * -math.sin(x) else: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -7.2e-15) || !(x <= 9.6e-45)) tmp = Float64(eps * Float64(-sin(x))); else tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -7.2e-15) || ~((x <= 9.6e-45))) tmp = eps * -sin(x); else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -7.2e-15], N[Not[LessEqual[x, 9.6e-45]], $MachinePrecision]], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-15} \lor \neg \left(x \leq 9.6 \cdot 10^{-45}\right):\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if x < -7.2000000000000002e-15 or 9.5999999999999996e-45 < x Initial program 8.8%
Taylor expanded in eps around 0 48.1%
mul-1-neg48.1%
*-commutative48.1%
distribute-rgt-neg-in48.1%
Simplified48.1%
if -7.2000000000000002e-15 < x < 9.5999999999999996e-45Initial program 74.5%
diff-cos92.1%
div-inv92.1%
associate--l+92.1%
metadata-eval92.1%
div-inv92.1%
+-commutative92.1%
associate-+l+92.1%
metadata-eval92.1%
Applied egg-rr92.1%
associate-*r*92.1%
*-commutative92.1%
*-commutative92.1%
+-commutative92.1%
count-292.1%
fma-def92.1%
sub-neg92.1%
mul-1-neg92.1%
+-commutative92.1%
associate-+r+99.6%
mul-1-neg99.6%
sub-neg99.6%
+-inverses99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
neg-sub099.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 91.2%
Final simplification68.5%
(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 39.9%
sub-neg39.9%
cos-sum64.3%
associate-+l-64.3%
fma-neg64.3%
Applied egg-rr64.3%
Taylor expanded in x around inf 64.3%
associate--r+91.0%
*-commutative91.0%
*-rgt-identity91.0%
distribute-lft-out--90.9%
sub-neg90.9%
metadata-eval90.9%
+-commutative90.9%
*-commutative90.9%
Simplified90.9%
distribute-lft-in91.0%
associate--l+64.3%
*-commutative64.3%
neg-mul-164.3%
cos-sum39.9%
+-commutative39.9%
sub-neg39.9%
diff-cos48.0%
div-inv48.0%
+-commutative48.0%
associate--l+75.7%
metadata-eval75.7%
div-inv75.7%
associate-+l+75.7%
metadata-eval75.7%
Applied egg-rr75.7%
+-inverses75.7%
+-rgt-identity75.7%
*-commutative75.7%
+-commutative75.7%
associate-+l+75.8%
Simplified75.8%
Final simplification75.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (* -0.5 (pow eps 2.0))))
(if (<= eps -8.5e-5)
t_0
(if (<= eps -3.1e-145)
t_1
(if (<= eps 1.9e-124) (* x (- eps)) (if (<= eps 1.1e-20) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = -0.5 * pow(eps, 2.0);
double tmp;
if (eps <= -8.5e-5) {
tmp = t_0;
} else if (eps <= -3.1e-145) {
tmp = t_1;
} else if (eps <= 1.9e-124) {
tmp = x * -eps;
} else if (eps <= 1.1e-20) {
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 = (-0.5d0) * (eps ** 2.0d0)
if (eps <= (-8.5d-5)) then
tmp = t_0
else if (eps <= (-3.1d-145)) then
tmp = t_1
else if (eps <= 1.9d-124) then
tmp = x * -eps
else if (eps <= 1.1d-20) 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 = -0.5 * Math.pow(eps, 2.0);
double tmp;
if (eps <= -8.5e-5) {
tmp = t_0;
} else if (eps <= -3.1e-145) {
tmp = t_1;
} else if (eps <= 1.9e-124) {
tmp = x * -eps;
} else if (eps <= 1.1e-20) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) t_1 = -0.5 * math.pow(eps, 2.0) tmp = 0 if eps <= -8.5e-5: tmp = t_0 elif eps <= -3.1e-145: tmp = t_1 elif eps <= 1.9e-124: tmp = x * -eps elif eps <= 1.1e-20: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(-0.5 * (eps ^ 2.0)) tmp = 0.0 if (eps <= -8.5e-5) tmp = t_0; elseif (eps <= -3.1e-145) tmp = t_1; elseif (eps <= 1.9e-124) tmp = Float64(x * Float64(-eps)); elseif (eps <= 1.1e-20) 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 = -0.5 * (eps ^ 2.0); tmp = 0.0; if (eps <= -8.5e-5) tmp = t_0; elseif (eps <= -3.1e-145) tmp = t_1; elseif (eps <= 1.9e-124) tmp = x * -eps; elseif (eps <= 1.1e-20) 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[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -8.5e-5], t$95$0, If[LessEqual[eps, -3.1e-145], t$95$1, If[LessEqual[eps, 1.9e-124], N[(x * (-eps)), $MachinePrecision], If[LessEqual[eps, 1.1e-20], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := -0.5 \cdot {\varepsilon}^{2}\\
\mathbf{if}\;\varepsilon \leq -8.5 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -3.1 \cdot 10^{-145}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 1.9 \cdot 10^{-124}:\\
\;\;\;\;x \cdot \left(-\varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 1.1 \cdot 10^{-20}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -8.500000000000001e-5 or 1.09999999999999995e-20 < eps Initial program 52.8%
Taylor expanded in x around 0 53.7%
if -8.500000000000001e-5 < eps < -3.1e-145 or 1.90000000000000006e-124 < eps < 1.09999999999999995e-20Initial program 5.5%
Taylor expanded in x around 0 5.7%
Taylor expanded in eps around 0 44.7%
if -3.1e-145 < eps < 1.90000000000000006e-124Initial program 39.3%
Taylor expanded in eps around 0 98.8%
mul-1-neg98.8%
*-commutative98.8%
distribute-rgt-neg-in98.8%
Simplified98.8%
Taylor expanded in x around 0 52.4%
associate-*r*52.4%
mul-1-neg52.4%
Simplified52.4%
Final simplification51.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.42) (not (<= eps 9.5e-7))) (+ -1.0 (cos eps)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.42) || !(eps <= 9.5e-7)) {
tmp = -1.0 + cos(eps);
} 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 <= (-0.42d0)) .or. (.not. (eps <= 9.5d-7))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.42) || !(eps <= 9.5e-7)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.42) or not (eps <= 9.5e-7): tmp = -1.0 + math.cos(eps) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.42) || !(eps <= 9.5e-7)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.42) || ~((eps <= 9.5e-7))) tmp = -1.0 + cos(eps); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.42], N[Not[LessEqual[eps, 9.5e-7]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.42 \lor \neg \left(\varepsilon \leq 9.5 \cdot 10^{-7}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -0.419999999999999984 or 9.5000000000000001e-7 < eps Initial program 53.9%
Taylor expanded in x around 0 54.9%
if -0.419999999999999984 < eps < 9.5000000000000001e-7Initial program 24.7%
Taylor expanded in eps around 0 80.3%
mul-1-neg80.3%
*-commutative80.3%
distribute-rgt-neg-in80.3%
Simplified80.3%
Final simplification67.1%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.05e-8) (not (<= eps 2.95e-52))) (+ -1.0 (cos eps)) (* x (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.05e-8) || !(eps <= 2.95e-52)) {
tmp = -1.0 + cos(eps);
} else {
tmp = 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 <= (-1.05d-8)) .or. (.not. (eps <= 2.95d-52))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = x * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.05e-8) || !(eps <= 2.95e-52)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = x * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.05e-8) or not (eps <= 2.95e-52): tmp = -1.0 + math.cos(eps) else: tmp = x * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.05e-8) || !(eps <= 2.95e-52)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(x * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.05e-8) || ~((eps <= 2.95e-52))) tmp = -1.0 + cos(eps); else tmp = x * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.05e-8], N[Not[LessEqual[eps, 2.95e-52]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(x * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.05 \cdot 10^{-8} \lor \neg \left(\varepsilon \leq 2.95 \cdot 10^{-52}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.04999999999999997e-8 or 2.9500000000000001e-52 < eps Initial program 50.4%
Taylor expanded in x around 0 51.4%
if -1.04999999999999997e-8 < eps < 2.9500000000000001e-52Initial program 26.3%
Taylor expanded in eps around 0 82.0%
mul-1-neg82.0%
*-commutative82.0%
distribute-rgt-neg-in82.0%
Simplified82.0%
Taylor expanded in x around 0 37.5%
associate-*r*37.5%
mul-1-neg37.5%
Simplified37.5%
Final simplification45.3%
(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 39.9%
Taylor expanded in eps around 0 40.4%
mul-1-neg40.4%
*-commutative40.4%
distribute-rgt-neg-in40.4%
Simplified40.4%
Taylor expanded in x around 0 18.1%
associate-*r*18.1%
mul-1-neg18.1%
Simplified18.1%
Final simplification18.1%
herbie shell --seed 2024024
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))