
(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 13 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 x) (cos eps)) (cos x)) (* (sin eps) (sin x)))
(* t_0 (* -2.0 (+ t_0 (* x (cos (* eps 0.5)))))))))
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(x) * cos(eps)) - cos(x)) - (sin(eps) * sin(x));
} else {
tmp = t_0 * (-2.0 * (t_0 + (x * cos((eps * 0.5)))));
}
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(x) * cos(eps)) - cos(x)) - (sin(eps) * sin(x))
else
tmp = t_0 * ((-2.0d0) * (t_0 + (x * cos((eps * 0.5d0)))))
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(x) * Math.cos(eps)) - Math.cos(x)) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = t_0 * (-2.0 * (t_0 + (x * Math.cos((eps * 0.5)))));
}
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(x) * math.cos(eps)) - math.cos(x)) - (math.sin(eps) * math.sin(x)) else: tmp = t_0 * (-2.0 * (t_0 + (x * math.cos((eps * 0.5))))) 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(x) * cos(eps)) - cos(x)) - Float64(sin(eps) * sin(x))); else tmp = Float64(t_0 * Float64(-2.0 * Float64(t_0 + Float64(x * cos(Float64(eps * 0.5)))))); 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(x) * cos(eps)) - cos(x)) - (sin(eps) * sin(x)); else tmp = t_0 * (-2.0 * (t_0 + (x * cos((eps * 0.5))))); 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[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(-2.0 * N[(t$95$0 + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 x \cdot \cos \varepsilon - \cos x\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(-2 \cdot \left(t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right)\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%
fma-neg55.7%
*-commutative55.7%
*-commutative55.7%
fma-neg55.7%
remove-double-neg55.7%
Simplified55.7%
Taylor expanded in eps 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%
distribute-rgt-in99.2%
mul-1-neg99.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%
associate-*l*88.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%
*-commutative98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around 0 99.6%
Final simplification99.4%
(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 39.9%
sub-neg39.9%
cos-sum64.3%
associate-+l-64.3%
fma-neg64.3%
Applied egg-rr64.3%
fma-neg64.3%
*-commutative64.3%
*-commutative64.3%
fma-neg64.3%
remove-double-neg64.3%
Simplified64.3%
Taylor expanded in eps 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%
div-inv90.7%
metadata-eval90.7%
1-sub-cos99.0%
pow299.0%
Applied egg-rr99.0%
associate-*r/99.0%
*-rgt-identity99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -1.7e-8) (not (<= x 1.5e-8)))
(- (/ (cos x) (/ 1.0 (+ -1.0 (cos eps)))) (* (sin eps) (sin x)))
(* t_0 (* -2.0 (+ t_0 (* x (cos (* eps 0.5)))))))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -1.7e-8) || !(x <= 1.5e-8)) {
tmp = (cos(x) / (1.0 / (-1.0 + cos(eps)))) - (sin(eps) * sin(x));
} else {
tmp = t_0 * (-2.0 * (t_0 + (x * cos((eps * 0.5)))));
}
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.7d-8)) .or. (.not. (x <= 1.5d-8))) then
tmp = (cos(x) / (1.0d0 / ((-1.0d0) + cos(eps)))) - (sin(eps) * sin(x))
else
tmp = t_0 * ((-2.0d0) * (t_0 + (x * cos((eps * 0.5d0)))))
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.7e-8) || !(x <= 1.5e-8)) {
tmp = (Math.cos(x) / (1.0 / (-1.0 + Math.cos(eps)))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = t_0 * (-2.0 * (t_0 + (x * Math.cos((eps * 0.5)))));
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -1.7e-8) or not (x <= 1.5e-8): tmp = (math.cos(x) / (1.0 / (-1.0 + math.cos(eps)))) - (math.sin(eps) * math.sin(x)) else: tmp = t_0 * (-2.0 * (t_0 + (x * math.cos((eps * 0.5))))) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -1.7e-8) || !(x <= 1.5e-8)) tmp = Float64(Float64(cos(x) / Float64(1.0 / Float64(-1.0 + cos(eps)))) - Float64(sin(eps) * sin(x))); else tmp = Float64(t_0 * Float64(-2.0 * Float64(t_0 + Float64(x * cos(Float64(eps * 0.5)))))); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -1.7e-8) || ~((x <= 1.5e-8))) tmp = (cos(x) / (1.0 / (-1.0 + cos(eps)))) - (sin(eps) * sin(x)); else tmp = t_0 * (-2.0 * (t_0 + (x * cos((eps * 0.5))))); 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.7e-8], N[Not[LessEqual[x, 1.5e-8]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] / N[(1.0 / N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(-2.0 * N[(t$95$0 + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -1.7 \cdot 10^{-8} \lor \neg \left(x \leq 1.5 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{\cos x}{\frac{1}{-1 + \cos \varepsilon}} - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(-2 \cdot \left(t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if x < -1.7e-8 or 1.49999999999999987e-8 < x Initial program 7.0%
sub-neg7.0%
cos-sum55.7%
associate-+l-55.7%
fma-neg55.7%
Applied egg-rr55.7%
fma-neg55.7%
*-commutative55.7%
*-commutative55.7%
fma-neg55.7%
remove-double-neg55.7%
Simplified55.7%
Taylor expanded in eps 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%
flip-+98.9%
div-inv98.9%
metadata-eval98.9%
1-sub-cos99.0%
pow299.0%
Applied egg-rr99.0%
associate-*r/99.0%
*-rgt-identity99.0%
Simplified99.0%
clear-num99.0%
un-div-inv99.0%
clear-num99.0%
unpow299.0%
1-sub-cos98.9%
metadata-eval98.9%
flip-+99.1%
Applied egg-rr99.1%
if -1.7e-8 < x < 1.49999999999999987e-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%
associate-*l*88.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%
*-commutative98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around 0 99.6%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -3.1e-10) (not (<= x 7e-9)))
(- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x)))
(* t_0 (* -2.0 (+ t_0 (* x (cos (* eps 0.5)))))))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -3.1e-10) || !(x <= 7e-9)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = t_0 * (-2.0 * (t_0 + (x * cos((eps * 0.5)))));
}
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 <= (-3.1d-10)) .or. (.not. (x <= 7d-9))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = t_0 * ((-2.0d0) * (t_0 + (x * cos((eps * 0.5d0)))))
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 <= -3.1e-10) || !(x <= 7e-9)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = t_0 * (-2.0 * (t_0 + (x * Math.cos((eps * 0.5)))));
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -3.1e-10) or not (x <= 7e-9): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = t_0 * (-2.0 * (t_0 + (x * math.cos((eps * 0.5))))) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -3.1e-10) || !(x <= 7e-9)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(t_0 * Float64(-2.0 * Float64(t_0 + Float64(x * cos(Float64(eps * 0.5)))))); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -3.1e-10) || ~((x <= 7e-9))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = t_0 * (-2.0 * (t_0 + (x * cos((eps * 0.5))))); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -3.1e-10], N[Not[LessEqual[x, 7e-9]], $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[(t$95$0 * N[(-2.0 * N[(t$95$0 + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -3.1 \cdot 10^{-10} \lor \neg \left(x \leq 7 \cdot 10^{-9}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(-2 \cdot \left(t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if x < -3.10000000000000015e-10 or 6.9999999999999998e-9 < x Initial program 7.0%
sub-neg7.0%
cos-sum55.7%
associate-+l-55.7%
fma-neg55.7%
Applied egg-rr55.7%
fma-neg55.7%
*-commutative55.7%
*-commutative55.7%
fma-neg55.7%
remove-double-neg55.7%
Simplified55.7%
Taylor expanded in eps 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 -3.10000000000000015e-10 < x < 6.9999999999999998e-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%
associate-*l*88.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%
*-commutative98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around 0 99.6%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ x eps)) (cos x)) -1e-16) (- (cos eps) (cos x)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((cos((x + eps)) - cos(x)) <= -1e-16) {
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-16)) 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-16) {
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-16: 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-16) 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-16) 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-16], 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^{-16}:\\
\;\;\;\;\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-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%
associate-*r*58.8%
mul-1-neg58.8%
Simplified58.8%
Final simplification65.9%
(FPCore (x eps) :precision binary64 (* (sin (* eps 0.5)) (* -2.0 (sin (* 0.5 (fma 2.0 x eps))))))
double code(double x, double eps) {
return sin((eps * 0.5)) * (-2.0 * sin((0.5 * fma(2.0, x, eps))));
}
function code(x, eps) return Float64(sin(Float64(eps * 0.5)) * Float64(-2.0 * sin(Float64(0.5 * fma(2.0, x, eps))))) end
code[x_, eps_] := N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(\varepsilon \cdot 0.5\right) \cdot \left(-2 \cdot \sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right)\right)
\end{array}
Initial program 39.9%
diff-cos48.0%
div-inv48.0%
associate--l+48.0%
metadata-eval48.0%
div-inv48.0%
+-commutative48.0%
associate-+l+48.1%
metadata-eval48.1%
Applied egg-rr48.1%
associate-*r*48.1%
*-commutative48.1%
associate-*l*48.1%
sub-neg48.1%
mul-1-neg48.1%
+-commutative48.1%
associate-+r+75.8%
mul-1-neg75.8%
sub-neg75.8%
+-inverses75.8%
remove-double-neg75.8%
mul-1-neg75.8%
sub-neg75.8%
neg-sub075.8%
mul-1-neg75.8%
remove-double-neg75.8%
*-commutative75.8%
+-commutative75.8%
Simplified75.8%
Final simplification75.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -7.2e-15) (not (<= x 9.2e-45)))
(* t_0 (* (sin x) -2.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 <= -7.2e-15) || !(x <= 9.2e-45)) {
tmp = t_0 * (sin(x) * -2.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 <= (-7.2d-15)) .or. (.not. (x <= 9.2d-45))) then
tmp = t_0 * (sin(x) * (-2.0d0))
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 <= -7.2e-15) || !(x <= 9.2e-45)) {
tmp = t_0 * (Math.sin(x) * -2.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 <= -7.2e-15) or not (x <= 9.2e-45): tmp = t_0 * (math.sin(x) * -2.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 <= -7.2e-15) || !(x <= 9.2e-45)) tmp = Float64(t_0 * Float64(sin(x) * -2.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 <= -7.2e-15) || ~((x <= 9.2e-45))) tmp = t_0 * (sin(x) * -2.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, -7.2e-15], N[Not[LessEqual[x, 9.2e-45]], $MachinePrecision]], N[(t$95$0 * N[(N[Sin[x], $MachinePrecision] * -2.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.2 \cdot 10^{-15} \lor \neg \left(x \leq 9.2 \cdot 10^{-45}\right):\\
\;\;\;\;t_0 \cdot \left(\sin x \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -7.2000000000000002e-15 or 9.19999999999999967e-45 < 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%
associate-*l*8.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%
*-commutative54.5%
+-commutative54.5%
Simplified54.5%
Taylor expanded in eps around 0 53.2%
if -7.2000000000000002e-15 < x < 9.19999999999999967e-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%
associate-*l*92.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%
*-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around 0 91.2%
Final simplification71.2%
(FPCore (x eps) :precision binary64 (* (* -2.0 (sin (/ (+ eps (- x x)) 2.0))) (sin (/ (+ x (+ x eps)) 2.0))))
double code(double x, double eps) {
return (-2.0 * sin(((eps + (x - x)) / 2.0))) * sin(((x + (x + eps)) / 2.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((-2.0d0) * sin(((eps + (x - x)) / 2.0d0))) * sin(((x + (x + eps)) / 2.0d0))
end function
public static double code(double x, double eps) {
return (-2.0 * Math.sin(((eps + (x - x)) / 2.0))) * Math.sin(((x + (x + eps)) / 2.0));
}
def code(x, eps): return (-2.0 * math.sin(((eps + (x - x)) / 2.0))) * math.sin(((x + (x + eps)) / 2.0))
function code(x, eps) return Float64(Float64(-2.0 * sin(Float64(Float64(eps + Float64(x - x)) / 2.0))) * sin(Float64(Float64(x + Float64(x + eps)) / 2.0))) end
function tmp = code(x, eps) tmp = (-2.0 * sin(((eps + (x - x)) / 2.0))) * sin(((x + (x + eps)) / 2.0)); end
code[x_, eps_] := N[(N[(-2.0 * N[Sin[N[(N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(N[(x + N[(x + eps), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-2 \cdot \sin \left(\frac{\varepsilon + \left(x - x\right)}{2}\right)\right) \cdot \sin \left(\frac{x + \left(x + \varepsilon\right)}{2}\right)
\end{array}
Initial program 39.9%
log1p-expm1-u39.7%
Applied egg-rr39.7%
log1p-expm1-u39.9%
diff-cos48.0%
Applied egg-rr48.0%
associate-*r*48.0%
+-commutative48.0%
associate--l+75.7%
associate-+l+75.7%
Simplified75.7%
Final simplification75.7%
(FPCore (x eps) :precision binary64 (if (or (<= x -8.2e-15) (not (<= x 1.5e-45))) (* (sin x) (- eps)) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -8.2e-15) || !(x <= 1.5e-45)) {
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 <= (-8.2d-15)) .or. (.not. (x <= 1.5d-45))) 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 <= -8.2e-15) || !(x <= 1.5e-45)) {
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 <= -8.2e-15) or not (x <= 1.5e-45): 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 <= -8.2e-15) || !(x <= 1.5e-45)) 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 <= -8.2e-15) || ~((x <= 1.5e-45))) 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, -8.2e-15], N[Not[LessEqual[x, 1.5e-45]], $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 -8.2 \cdot 10^{-15} \lor \neg \left(x \leq 1.5 \cdot 10^{-45}\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 < -8.20000000000000072e-15 or 1.50000000000000005e-45 < x Initial program 8.8%
Taylor expanded in eps around 0 48.1%
associate-*r*48.1%
mul-1-neg48.1%
Simplified48.1%
if -8.20000000000000072e-15 < x < 1.50000000000000005e-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%
associate-*l*92.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%
*-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around 0 91.2%
Final simplification68.5%
(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.8e-140)
t_1
(if (<= eps 7.2e-127) (* eps (- x)) (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.8e-140) {
tmp = t_1;
} else if (eps <= 7.2e-127) {
tmp = eps * -x;
} 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.8d-140)) then
tmp = t_1
else if (eps <= 7.2d-127) then
tmp = eps * -x
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.8e-140) {
tmp = t_1;
} else if (eps <= 7.2e-127) {
tmp = eps * -x;
} 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.8e-140: tmp = t_1 elif eps <= 7.2e-127: tmp = eps * -x 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.8e-140) tmp = t_1; elseif (eps <= 7.2e-127) tmp = Float64(eps * Float64(-x)); 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.8e-140) tmp = t_1; elseif (eps <= 7.2e-127) tmp = eps * -x; 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.8e-140], t$95$1, If[LessEqual[eps, 7.2e-127], N[(eps * (-x)), $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.8 \cdot 10^{-140}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 7.2 \cdot 10^{-127}:\\
\;\;\;\;\varepsilon \cdot \left(-x\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.79999999999999998e-140 or 7.1999999999999999e-127 < 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.79999999999999998e-140 < eps < 7.1999999999999999e-127Initial program 39.3%
diff-cos40.5%
div-inv40.5%
associate--l+40.5%
metadata-eval40.5%
div-inv40.5%
+-commutative40.5%
associate-+l+40.5%
metadata-eval40.5%
Applied egg-rr40.5%
associate-*r*40.5%
*-commutative40.5%
associate-*l*40.5%
sub-neg40.5%
mul-1-neg40.5%
+-commutative40.5%
associate-+r+99.8%
mul-1-neg99.8%
sub-neg99.8%
+-inverses99.8%
remove-double-neg99.8%
mul-1-neg99.8%
sub-neg99.8%
neg-sub099.8%
mul-1-neg99.8%
remove-double-neg99.8%
*-commutative99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in eps around 0 98.8%
neg-mul-198.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 2.6e-6))) (+ -1.0 (cos eps)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.42) || !(eps <= 2.6e-6)) {
tmp = -1.0 + cos(eps);
} else {
tmp = sin(x) * -eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.42d0)) .or. (.not. (eps <= 2.6d-6))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.42) || !(eps <= 2.6e-6)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.42) or not (eps <= 2.6e-6): tmp = -1.0 + math.cos(eps) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.42) || !(eps <= 2.6e-6)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.42) || ~((eps <= 2.6e-6))) tmp = -1.0 + cos(eps); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.42], N[Not[LessEqual[eps, 2.6e-6]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.42 \lor \neg \left(\varepsilon \leq 2.6 \cdot 10^{-6}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -0.419999999999999984 or 2.60000000000000009e-6 < eps Initial program 53.9%
Taylor expanded in x around 0 54.9%
if -0.419999999999999984 < eps < 2.60000000000000009e-6Initial program 24.7%
Taylor expanded in eps around 0 80.3%
associate-*r*80.3%
mul-1-neg80.3%
Simplified80.3%
Final simplification67.1%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.05e-8) (not (<= eps 2.35e-52))) (+ -1.0 (cos eps)) (* eps (- x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.05e-8) || !(eps <= 2.35e-52)) {
tmp = -1.0 + cos(eps);
} else {
tmp = eps * -x;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.05d-8)) .or. (.not. (eps <= 2.35d-52))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = eps * -x
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.05e-8) || !(eps <= 2.35e-52)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * -x;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.05e-8) or not (eps <= 2.35e-52): tmp = -1.0 + math.cos(eps) else: tmp = eps * -x return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.05e-8) || !(eps <= 2.35e-52)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(eps * Float64(-x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.05e-8) || ~((eps <= 2.35e-52))) tmp = -1.0 + cos(eps); else tmp = eps * -x; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.05e-8], N[Not[LessEqual[eps, 2.35e-52]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.05 \cdot 10^{-8} \lor \neg \left(\varepsilon \leq 2.35 \cdot 10^{-52}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\end{array}
\end{array}
if eps < -1.04999999999999997e-8 or 2.3499999999999999e-52 < eps Initial program 50.4%
Taylor expanded in x around 0 51.4%
if -1.04999999999999997e-8 < eps < 2.3499999999999999e-52Initial program 26.3%
diff-cos44.5%
div-inv44.5%
associate--l+44.6%
metadata-eval44.6%
div-inv44.6%
+-commutative44.6%
associate-+l+44.6%
metadata-eval44.6%
Applied egg-rr44.6%
associate-*r*44.6%
*-commutative44.6%
associate-*l*44.6%
sub-neg44.6%
mul-1-neg44.6%
+-commutative44.6%
associate-+r+99.8%
mul-1-neg99.8%
sub-neg99.8%
+-inverses99.8%
remove-double-neg99.8%
mul-1-neg99.8%
sub-neg99.8%
neg-sub099.8%
mul-1-neg99.8%
remove-double-neg99.8%
*-commutative99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in eps around 0 82.0%
neg-mul-182.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 (* eps (- x)))
double code(double x, double eps) {
return eps * -x;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * -x
end function
public static double code(double x, double eps) {
return eps * -x;
}
def code(x, eps): return eps * -x
function code(x, eps) return Float64(eps * Float64(-x)) end
function tmp = code(x, eps) tmp = eps * -x; end
code[x_, eps_] := N[(eps * (-x)), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(-x\right)
\end{array}
Initial program 39.9%
diff-cos48.0%
div-inv48.0%
associate--l+48.0%
metadata-eval48.0%
div-inv48.0%
+-commutative48.0%
associate-+l+48.1%
metadata-eval48.1%
Applied egg-rr48.1%
associate-*r*48.1%
*-commutative48.1%
associate-*l*48.1%
sub-neg48.1%
mul-1-neg48.1%
+-commutative48.1%
associate-+r+75.8%
mul-1-neg75.8%
sub-neg75.8%
+-inverses75.8%
remove-double-neg75.8%
mul-1-neg75.8%
sub-neg75.8%
neg-sub075.8%
mul-1-neg75.8%
remove-double-neg75.8%
*-commutative75.8%
+-commutative75.8%
Simplified75.8%
Taylor expanded in eps around 0 40.4%
neg-mul-140.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)))