
(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 (if (or (<= eps -4e-5) (not (<= eps 4.4e-5))) (fma (+ -1.0 (cos eps)) (cos x) (* (sin eps) (- (sin x)))) (- (* -0.5 (* eps (* (cos x) eps))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4e-5) || !(eps <= 4.4e-5)) {
tmp = fma((-1.0 + cos(eps)), cos(x), (sin(eps) * -sin(x)));
} else {
tmp = (-0.5 * (eps * (cos(x) * eps))) - (eps * sin(x));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -4e-5) || !(eps <= 4.4e-5)) tmp = fma(Float64(-1.0 + cos(eps)), cos(x), Float64(sin(eps) * Float64(-sin(x)))); else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(cos(x) * eps))) - Float64(eps * sin(x))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -4e-5], N[Not[LessEqual[eps, 4.4e-5]], $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[(-0.5 * N[(eps * N[(N[Cos[x], $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 4.4 \cdot 10^{-5}\right):\\
\;\;\;\;\mathsf{fma}\left(-1 + \cos \varepsilon, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\cos x \cdot \varepsilon\right)\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -4.00000000000000033e-5 or 4.3999999999999999e-5 < eps Initial program 54.3%
sub-neg54.3%
cos-sum99.2%
associate-+l-99.2%
fma-neg99.3%
Applied egg-rr99.3%
fma-neg99.2%
*-commutative99.2%
*-commutative99.2%
fma-neg99.2%
remove-double-neg99.2%
Simplified99.2%
Taylor expanded in eps around inf 99.2%
associate--r+99.3%
*-rgt-identity99.3%
distribute-lft-out--99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
Simplified99.3%
cancel-sign-sub-inv99.3%
*-commutative99.3%
fma-def99.4%
Applied egg-rr99.4%
if -4.00000000000000033e-5 < eps < 4.3999999999999999e-5Initial program 19.5%
Taylor expanded in eps around 0 99.8%
mul-1-neg99.8%
unsub-neg99.8%
unpow299.8%
associate-*l*99.8%
Simplified99.8%
Final simplification99.6%
(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 38.2%
sub-neg38.2%
cos-sum62.6%
associate-+l-62.6%
fma-neg62.6%
Applied egg-rr62.6%
fma-neg62.6%
*-commutative62.6%
*-commutative62.6%
fma-neg62.6%
remove-double-neg62.6%
Simplified62.6%
Taylor expanded in eps around inf 62.6%
associate--r+90.2%
*-rgt-identity90.2%
distribute-lft-out--90.3%
sub-neg90.3%
metadata-eval90.3%
+-commutative90.3%
Simplified90.3%
flip-+89.7%
metadata-eval89.7%
1-sub-cos98.9%
pow298.8%
Applied egg-rr98.8%
Final simplification98.8%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.6e-5) (not (<= eps 3.6e-5))) (- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x))) (- (* -0.5 (* eps (* (cos x) eps))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.6e-5) || !(eps <= 3.6e-5)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = (-0.5 * (eps * (cos(x) * eps))) - (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 <= (-4.6d-5)) .or. (.not. (eps <= 3.6d-5))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = ((-0.5d0) * (eps * (cos(x) * eps))) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -4.6e-5) || !(eps <= 3.6e-5)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = (-0.5 * (eps * (Math.cos(x) * eps))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4.6e-5) or not (eps <= 3.6e-5): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = (-0.5 * (eps * (math.cos(x) * eps))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -4.6e-5) || !(eps <= 3.6e-5)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(cos(x) * eps))) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -4.6e-5) || ~((eps <= 3.6e-5))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = (-0.5 * (eps * (cos(x) * eps))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.6e-5], N[Not[LessEqual[eps, 3.6e-5]], $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[(-0.5 * N[(eps * N[(N[Cos[x], $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.6 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 3.6 \cdot 10^{-5}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\cos x \cdot \varepsilon\right)\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -4.6e-5 or 3.60000000000000009e-5 < eps Initial program 54.3%
sub-neg54.3%
cos-sum99.2%
associate-+l-99.2%
fma-neg99.3%
Applied egg-rr99.3%
fma-neg99.2%
*-commutative99.2%
*-commutative99.2%
fma-neg99.2%
remove-double-neg99.2%
Simplified99.2%
Taylor expanded in eps around inf 99.2%
associate--r+99.3%
*-rgt-identity99.3%
distribute-lft-out--99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
Simplified99.3%
if -4.6e-5 < eps < 3.60000000000000009e-5Initial program 19.5%
Taylor expanded in eps around 0 99.8%
mul-1-neg99.8%
unsub-neg99.8%
unpow299.8%
associate-*l*99.8%
Simplified99.8%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0125) (not (<= eps 0.0075))) (- (cos eps) (cos x)) (- (* -0.5 (* eps (* (cos x) eps))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0125) || !(eps <= 0.0075)) {
tmp = cos(eps) - cos(x);
} else {
tmp = (-0.5 * (eps * (cos(x) * eps))) - (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.0125d0)) .or. (.not. (eps <= 0.0075d0))) then
tmp = cos(eps) - cos(x)
else
tmp = ((-0.5d0) * (eps * (cos(x) * eps))) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0125) || !(eps <= 0.0075)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = (-0.5 * (eps * (Math.cos(x) * eps))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0125) or not (eps <= 0.0075): tmp = math.cos(eps) - math.cos(x) else: tmp = (-0.5 * (eps * (math.cos(x) * eps))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0125) || !(eps <= 0.0075)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(cos(x) * eps))) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0125) || ~((eps <= 0.0075))) tmp = cos(eps) - cos(x); else tmp = (-0.5 * (eps * (cos(x) * eps))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0125], N[Not[LessEqual[eps, 0.0075]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(eps * N[(N[Cos[x], $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0125 \lor \neg \left(\varepsilon \leq 0.0075\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\cos x \cdot \varepsilon\right)\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -0.012500000000000001 or 0.0074999999999999997 < eps Initial program 54.3%
Taylor expanded in x around 0 57.5%
if -0.012500000000000001 < eps < 0.0074999999999999997Initial program 19.5%
Taylor expanded in eps around 0 99.8%
mul-1-neg99.8%
unsub-neg99.8%
unpow299.8%
associate-*l*99.8%
Simplified99.8%
Final simplification77.2%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 (- eps (* x -2.0)))) (sin (* eps 0.5)))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * (eps - (x * -2.0)))) * sin((eps * 0.5)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((0.5d0 * (eps - (x * (-2.0d0))))) * sin((eps * 0.5d0)))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * (eps - (x * -2.0)))) * Math.sin((eps * 0.5)));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * (eps - (x * -2.0)))) * math.sin((eps * 0.5)))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))) * sin(Float64(eps * 0.5)))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * (eps - (x * -2.0)))) * sin((eps * 0.5))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * N[(eps - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 38.2%
diff-cos47.4%
div-inv47.4%
metadata-eval47.4%
div-inv47.4%
+-commutative47.4%
metadata-eval47.4%
Applied egg-rr47.4%
*-commutative47.4%
+-commutative47.4%
associate--l+76.1%
+-inverses76.1%
distribute-lft-in76.1%
metadata-eval76.1%
*-commutative76.1%
+-commutative76.1%
Simplified76.1%
Taylor expanded in x around -inf 76.0%
Final simplification76.0%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 (+ x (+ x eps)))) (sin (* eps 0.5)))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * (x + (x + eps)))) * sin((eps * 0.5)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((0.5d0 * (x + (x + eps)))) * sin((eps * 0.5d0)))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * (x + (x + eps)))) * Math.sin((eps * 0.5)));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * (x + (x + eps)))) * math.sin((eps * 0.5)))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * Float64(x + Float64(x + eps)))) * sin(Float64(eps * 0.5)))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * (x + (x + eps)))) * sin((eps * 0.5))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * N[(x + N[(x + eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \left(x + \left(x + \varepsilon\right)\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 38.2%
diff-cos47.4%
div-inv47.4%
metadata-eval47.4%
div-inv47.4%
+-commutative47.4%
metadata-eval47.4%
Applied egg-rr47.4%
*-commutative47.4%
+-commutative47.4%
associate--l+76.1%
+-inverses76.1%
distribute-lft-in76.1%
metadata-eval76.1%
*-commutative76.1%
+-commutative76.1%
Simplified76.1%
log1p-expm1-u76.1%
log1p-udef59.6%
+-commutative59.6%
Applied egg-rr59.6%
expm1-log1p-u59.6%
expm1-udef39.0%
*-commutative39.0%
log1p-def39.0%
log1p-expm1-u39.0%
+-commutative39.0%
+-rgt-identity39.0%
*-commutative39.0%
Applied egg-rr39.0%
expm1-def76.0%
expm1-log1p76.1%
*-commutative76.1%
Simplified76.1%
Final simplification76.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -7e-39) (not (<= x 1.55e-30)))
(* -2.0 (* (sin x) t_0))
(* -2.0 (pow t_0 2.0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -7e-39) || !(x <= 1.55e-30)) {
tmp = -2.0 * (sin(x) * t_0);
} else {
tmp = -2.0 * pow(t_0, 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((eps * 0.5d0))
if ((x <= (-7d-39)) .or. (.not. (x <= 1.55d-30))) then
tmp = (-2.0d0) * (sin(x) * t_0)
else
tmp = (-2.0d0) * (t_0 ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
double tmp;
if ((x <= -7e-39) || !(x <= 1.55e-30)) {
tmp = -2.0 * (Math.sin(x) * t_0);
} else {
tmp = -2.0 * Math.pow(t_0, 2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -7e-39) or not (x <= 1.55e-30): tmp = -2.0 * (math.sin(x) * t_0) else: tmp = -2.0 * math.pow(t_0, 2.0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -7e-39) || !(x <= 1.55e-30)) tmp = Float64(-2.0 * Float64(sin(x) * t_0)); else tmp = Float64(-2.0 * (t_0 ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -7e-39) || ~((x <= 1.55e-30))) tmp = -2.0 * (sin(x) * t_0); else tmp = -2.0 * (t_0 ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -7e-39], N[Not[LessEqual[x, 1.55e-30]], $MachinePrecision]], N[(-2.0 * N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -7 \cdot 10^{-39} \lor \neg \left(x \leq 1.55 \cdot 10^{-30}\right):\\
\;\;\;\;-2 \cdot \left(\sin x \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -6.99999999999999999e-39 or 1.54999999999999995e-30 < x Initial program 10.8%
diff-cos11.0%
div-inv11.0%
metadata-eval11.0%
div-inv11.0%
+-commutative11.0%
metadata-eval11.0%
Applied egg-rr11.0%
*-commutative11.0%
+-commutative11.0%
associate--l+57.3%
+-inverses57.3%
distribute-lft-in57.3%
metadata-eval57.3%
*-commutative57.3%
+-commutative57.3%
Simplified57.3%
Taylor expanded in eps around 0 53.9%
if -6.99999999999999999e-39 < x < 1.54999999999999995e-30Initial program 72.2%
diff-cos92.8%
div-inv92.8%
metadata-eval92.8%
div-inv92.8%
+-commutative92.8%
metadata-eval92.8%
Applied egg-rr92.8%
*-commutative92.8%
+-commutative92.8%
associate--l+99.5%
+-inverses99.5%
distribute-lft-in99.5%
metadata-eval99.5%
*-commutative99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in x around 0 91.9%
Final simplification70.8%
(FPCore (x eps) :precision binary64 (if (or (<= x -1.65e-38) (not (<= x 2.15e-30))) (* eps (- (sin x))) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -1.65e-38) || !(x <= 2.15e-30)) {
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 <= (-1.65d-38)) .or. (.not. (x <= 2.15d-30))) 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 <= -1.65e-38) || !(x <= 2.15e-30)) {
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 <= -1.65e-38) or not (x <= 2.15e-30): 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 <= -1.65e-38) || !(x <= 2.15e-30)) 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 <= -1.65e-38) || ~((x <= 2.15e-30))) 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, -1.65e-38], N[Not[LessEqual[x, 2.15e-30]], $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 -1.65 \cdot 10^{-38} \lor \neg \left(x \leq 2.15 \cdot 10^{-30}\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 < -1.6500000000000001e-38 or 2.14999999999999983e-30 < x Initial program 10.8%
Taylor expanded in eps around 0 50.5%
associate-*r*50.5%
mul-1-neg50.5%
Simplified50.5%
if -1.6500000000000001e-38 < x < 2.14999999999999983e-30Initial program 72.2%
diff-cos92.8%
div-inv92.8%
metadata-eval92.8%
div-inv92.8%
+-commutative92.8%
metadata-eval92.8%
Applied egg-rr92.8%
*-commutative92.8%
+-commutative92.8%
associate--l+99.5%
+-inverses99.5%
distribute-lft-in99.5%
metadata-eval99.5%
*-commutative99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in x around 0 91.9%
Final simplification68.9%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.8e-7) (not (<= eps 5.2e-7))) (- (cos eps) (cos x)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.8e-7) || !(eps <= 5.2e-7)) {
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 ((eps <= (-4.8d-7)) .or. (.not. (eps <= 5.2d-7))) 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 ((eps <= -4.8e-7) || !(eps <= 5.2e-7)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4.8e-7) or not (eps <= 5.2e-7): tmp = math.cos(eps) - math.cos(x) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -4.8e-7) || !(eps <= 5.2e-7)) 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 ((eps <= -4.8e-7) || ~((eps <= 5.2e-7))) tmp = cos(eps) - cos(x); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.8e-7], N[Not[LessEqual[eps, 5.2e-7]], $MachinePrecision]], 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}\;\varepsilon \leq -4.8 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 5.2 \cdot 10^{-7}\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -4.79999999999999957e-7 or 5.19999999999999998e-7 < eps Initial program 54.3%
Taylor expanded in x around 0 57.5%
if -4.79999999999999957e-7 < eps < 5.19999999999999998e-7Initial program 19.5%
Taylor expanded in eps around 0 79.8%
associate-*r*79.8%
mul-1-neg79.8%
Simplified79.8%
Final simplification67.9%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0001) (not (<= eps 1e-6))) (+ -1.0 (cos eps)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0001) || !(eps <= 1e-6)) {
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.0001d0)) .or. (.not. (eps <= 1d-6))) 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.0001) || !(eps <= 1e-6)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0001) or not (eps <= 1e-6): tmp = -1.0 + math.cos(eps) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0001) || !(eps <= 1e-6)) 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.0001) || ~((eps <= 1e-6))) tmp = -1.0 + cos(eps); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0001], N[Not[LessEqual[eps, 1e-6]], $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.0001 \lor \neg \left(\varepsilon \leq 10^{-6}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -1.00000000000000005e-4 or 9.99999999999999955e-7 < eps Initial program 54.3%
Taylor expanded in x around 0 56.0%
if -1.00000000000000005e-4 < eps < 9.99999999999999955e-7Initial program 19.5%
Taylor expanded in eps around 0 79.8%
associate-*r*79.8%
mul-1-neg79.8%
Simplified79.8%
Final simplification67.1%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.95e-20) (not (<= eps 0.00016))) (+ -1.0 (cos eps)) (* eps (* eps -0.5))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.95e-20) || !(eps <= 0.00016)) {
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.95d-20)) .or. (.not. (eps <= 0.00016d0))) 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.95e-20) || !(eps <= 0.00016)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * (eps * -0.5);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.95e-20) or not (eps <= 0.00016): tmp = -1.0 + math.cos(eps) else: tmp = eps * (eps * -0.5) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.95e-20) || !(eps <= 0.00016)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(eps * Float64(eps * -0.5)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.95e-20) || ~((eps <= 0.00016))) tmp = -1.0 + cos(eps); else tmp = eps * (eps * -0.5); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.95e-20], N[Not[LessEqual[eps, 0.00016]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.95 \cdot 10^{-20} \lor \neg \left(\varepsilon \leq 0.00016\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\end{array}
\end{array}
if eps < -1.95000000000000004e-20 or 1.60000000000000013e-4 < eps Initial program 53.3%
Taylor expanded in x around 0 54.9%
if -1.95000000000000004e-20 < eps < 1.60000000000000013e-4Initial program 20.0%
Taylor expanded in x around 0 20.0%
Taylor expanded in eps around 0 39.7%
unpow239.7%
associate-*r*39.7%
*-commutative39.7%
Simplified39.7%
Final simplification48.0%
(FPCore (x eps) :precision binary64 (* eps (* eps -0.5)))
double code(double x, double eps) {
return eps * (eps * -0.5);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * (eps * (-0.5d0))
end function
public static double code(double x, double eps) {
return eps * (eps * -0.5);
}
def code(x, eps): return eps * (eps * -0.5)
function code(x, eps) return Float64(eps * Float64(eps * -0.5)) end
function tmp = code(x, eps) tmp = eps * (eps * -0.5); end
code[x_, eps_] := N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)
\end{array}
Initial program 38.2%
Taylor expanded in x around 0 39.0%
Taylor expanded in eps around 0 20.0%
unpow220.0%
associate-*r*20.0%
*-commutative20.0%
Simplified20.0%
Final simplification20.0%
(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 38.2%
add-cube-cbrt38.0%
pow338.1%
Applied egg-rr38.1%
Taylor expanded in eps around 0 10.8%
pow-base-110.8%
*-rgt-identity10.8%
+-inverses10.8%
Simplified10.8%
Final simplification10.8%
herbie shell --seed 2023228
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))