
(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 (* 0.5 eps)))) (* -2.0 (* t_0 (fma (cos x) t_0 (* (sin x) (cos (* 0.5 eps))))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * fma(cos(x), t_0, (sin(x) * cos((0.5 * eps)))));
}
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * fma(cos(x), t_0, Float64(sin(x) * cos(Float64(0.5 * eps)))))) end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(-2.0 * N[(t$95$0 * N[(N[Cos[x], $MachinePrecision] * t$95$0 + N[(N[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
-2 \cdot \left(t_0 \cdot \mathsf{fma}\left(\cos x, t_0, \sin x \cdot \cos \left(0.5 \cdot \varepsilon\right)\right)\right)
\end{array}
\end{array}
Initial program 41.6%
diff-cos48.6%
div-inv48.6%
metadata-eval48.6%
div-inv48.6%
+-commutative48.6%
metadata-eval48.6%
Applied egg-rr48.6%
*-commutative48.6%
+-commutative48.6%
associate--l+77.2%
*-commutative77.2%
associate-+r+77.7%
+-commutative77.7%
Simplified77.7%
distribute-lft-in77.7%
sin-sum99.4%
Applied egg-rr99.4%
*-commutative99.4%
count-299.4%
*-commutative99.4%
count-299.4%
*-commutative99.4%
count-299.4%
*-commutative99.4%
count-299.4%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.4%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (+ (* (sin x) (cos (* 0.5 eps))) (* t_0 (cos x)))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * ((sin(x) * cos((0.5 * eps))) + (t_0 * cos(x))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = sin((0.5d0 * eps))
code = (-2.0d0) * (t_0 * ((sin(x) * cos((0.5d0 * eps))) + (t_0 * cos(x))))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
return -2.0 * (t_0 * ((Math.sin(x) * Math.cos((0.5 * eps))) + (t_0 * Math.cos(x))));
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) return -2.0 * (t_0 * ((math.sin(x) * math.cos((0.5 * eps))) + (t_0 * math.cos(x))))
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * Float64(Float64(sin(x) * cos(Float64(0.5 * eps))) + Float64(t_0 * cos(x))))) end
function tmp = code(x, eps) t_0 = sin((0.5 * eps)); tmp = -2.0 * (t_0 * ((sin(x) * cos((0.5 * eps))) + (t_0 * cos(x)))); end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(-2.0 * N[(t$95$0 * N[(N[(N[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
-2 \cdot \left(t_0 \cdot \left(\sin x \cdot \cos \left(0.5 \cdot \varepsilon\right) + t_0 \cdot \cos x\right)\right)
\end{array}
\end{array}
Initial program 41.6%
diff-cos48.6%
div-inv48.6%
metadata-eval48.6%
div-inv48.6%
+-commutative48.6%
metadata-eval48.6%
Applied egg-rr48.6%
*-commutative48.6%
+-commutative48.6%
associate--l+77.2%
*-commutative77.2%
associate-+r+77.7%
+-commutative77.7%
Simplified77.7%
distribute-lft-in77.7%
sin-sum99.4%
Applied egg-rr99.4%
*-commutative99.4%
count-299.4%
*-commutative99.4%
count-299.4%
*-commutative99.4%
count-299.4%
*-commutative99.4%
count-299.4%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.4%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* 0.5 eps))))
(if (or (<= x -1.9e-8) (not (<= x 5.5e-53)))
(fma (sin x) (- (sin eps)) (* (cos x) (+ -1.0 (cos eps))))
(* -2.0 (* t_0 (+ t_0 (* x (cos (* 0.5 eps)))))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
double tmp;
if ((x <= -1.9e-8) || !(x <= 5.5e-53)) {
tmp = fma(sin(x), -sin(eps), (cos(x) * (-1.0 + cos(eps))));
} else {
tmp = -2.0 * (t_0 * (t_0 + (x * cos((0.5 * eps)))));
}
return tmp;
}
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) tmp = 0.0 if ((x <= -1.9e-8) || !(x <= 5.5e-53)) tmp = fma(sin(x), Float64(-sin(eps)), Float64(cos(x) * Float64(-1.0 + cos(eps)))); else tmp = Float64(-2.0 * Float64(t_0 * Float64(t_0 + Float64(x * cos(Float64(0.5 * eps)))))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -1.9e-8], N[Not[LessEqual[x, 5.5e-53]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(t$95$0 * N[(t$95$0 + N[(x * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
\mathbf{if}\;x \leq -1.9 \cdot 10^{-8} \lor \neg \left(x \leq 5.5 \cdot 10^{-53}\right):\\
\;\;\;\;\mathsf{fma}\left(\sin x, -\sin \varepsilon, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(t_0 + x \cdot \cos \left(0.5 \cdot \varepsilon\right)\right)\right)\\
\end{array}
\end{array}
if x < -1.90000000000000014e-8 or 5.50000000000000023e-53 < x Initial program 11.2%
cos-sum54.4%
sub-neg54.4%
Applied egg-rr54.4%
+-commutative54.4%
distribute-lft-neg-in54.4%
*-commutative54.4%
fma-def54.4%
*-commutative54.4%
Simplified54.4%
Taylor expanded in eps around inf 54.4%
neg-mul-154.4%
associate--l+99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
fma-def99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.4%
sub-neg99.4%
metadata-eval99.4%
+-commutative99.4%
Simplified99.4%
if -1.90000000000000014e-8 < x < 5.50000000000000023e-53Initial program 77.2%
diff-cos92.5%
div-inv92.5%
metadata-eval92.5%
div-inv92.5%
+-commutative92.5%
metadata-eval92.5%
Applied egg-rr92.5%
*-commutative92.5%
+-commutative92.5%
associate--l+99.2%
*-commutative99.2%
associate-+r+99.2%
+-commutative99.2%
Simplified99.2%
distribute-lft-in99.2%
sin-sum99.5%
Applied egg-rr99.5%
*-commutative99.5%
count-299.5%
*-commutative99.5%
count-299.5%
*-commutative99.5%
count-299.5%
*-commutative99.5%
count-299.5%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.5%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in x around 0 99.5%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= x -2.7e-49) (not (<= x 6.5e-22))) (* -2.0 (* (sin x) (sin (* 0.5 (+ eps (- x x)))))) (* -2.0 (pow (sin (* 0.5 eps)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -2.7e-49) || !(x <= 6.5e-22)) {
tmp = -2.0 * (sin(x) * sin((0.5 * (eps + (x - x)))));
} else {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-2.7d-49)) .or. (.not. (x <= 6.5d-22))) then
tmp = (-2.0d0) * (sin(x) * sin((0.5d0 * (eps + (x - x)))))
else
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -2.7e-49) || !(x <= 6.5e-22)) {
tmp = -2.0 * (Math.sin(x) * Math.sin((0.5 * (eps + (x - x)))));
} else {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -2.7e-49) or not (x <= 6.5e-22): tmp = -2.0 * (math.sin(x) * math.sin((0.5 * (eps + (x - x))))) else: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -2.7e-49) || !(x <= 6.5e-22)) tmp = Float64(-2.0 * Float64(sin(x) * sin(Float64(0.5 * Float64(eps + Float64(x - x)))))); else tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -2.7e-49) || ~((x <= 6.5e-22))) tmp = -2.0 * (sin(x) * sin((0.5 * (eps + (x - x))))); else tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -2.7e-49], N[Not[LessEqual[x, 6.5e-22]], $MachinePrecision]], N[(-2.0 * N[(N[Sin[x], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-49} \lor \neg \left(x \leq 6.5 \cdot 10^{-22}\right):\\
\;\;\;\;-2 \cdot \left(\sin x \cdot \sin \left(0.5 \cdot \left(\varepsilon + \left(x - x\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\end{array}
\end{array}
if x < -2.7e-49 or 6.50000000000000043e-22 < x Initial program 7.0%
diff-cos7.6%
div-inv7.6%
metadata-eval7.6%
div-inv7.6%
+-commutative7.6%
metadata-eval7.6%
Applied egg-rr7.6%
*-commutative7.6%
+-commutative7.6%
associate--l+57.3%
*-commutative57.3%
associate-+r+58.2%
+-commutative58.2%
Simplified58.2%
Taylor expanded in eps around 0 55.5%
if -2.7e-49 < x < 6.50000000000000043e-22Initial program 80.3%
diff-cos94.4%
div-inv94.4%
metadata-eval94.4%
div-inv94.4%
+-commutative94.4%
metadata-eval94.4%
Applied egg-rr94.4%
*-commutative94.4%
+-commutative94.4%
associate--l+99.5%
*-commutative99.5%
associate-+r+99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in x around 0 93.3%
Final simplification73.4%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.0052)
(* -2.0 (pow (sin (* 0.5 eps)) 2.0))
(if (<= eps 0.00225)
(- (* -0.5 (* eps (* eps (cos x)))) (* eps (sin x)))
(- (cos eps) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0052) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
} else if (eps <= 0.00225) {
tmp = (-0.5 * (eps * (eps * cos(x)))) - (eps * sin(x));
} else {
tmp = cos(eps) - cos(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.0052d0)) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
else if (eps <= 0.00225d0) then
tmp = ((-0.5d0) * (eps * (eps * cos(x)))) - (eps * sin(x))
else
tmp = cos(eps) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -0.0052) {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
} else if (eps <= 0.00225) {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) - (eps * Math.sin(x));
} else {
tmp = Math.cos(eps) - Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.0052: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) elif eps <= 0.00225: tmp = (-0.5 * (eps * (eps * math.cos(x)))) - (eps * math.sin(x)) else: tmp = math.cos(eps) - math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.0052) tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); elseif (eps <= 0.00225) tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) - Float64(eps * sin(x))); else tmp = Float64(cos(eps) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -0.0052) tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); elseif (eps <= 0.00225) tmp = (-0.5 * (eps * (eps * cos(x)))) - (eps * sin(x)); else tmp = cos(eps) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.0052], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00225], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0052:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{elif}\;\varepsilon \leq 0.00225:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) - \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\end{array}
\end{array}
if eps < -0.0051999999999999998Initial program 54.5%
diff-cos54.5%
div-inv54.5%
metadata-eval54.5%
div-inv54.5%
+-commutative54.5%
metadata-eval54.5%
Applied egg-rr54.5%
*-commutative54.5%
+-commutative54.5%
associate--l+57.6%
*-commutative57.6%
associate-+r+59.4%
+-commutative59.4%
Simplified59.4%
Taylor expanded in x around 0 57.4%
if -0.0051999999999999998 < eps < 0.00224999999999999983Initial program 28.2%
Taylor expanded in eps around 0 99.6%
mul-1-neg99.6%
unsub-neg99.6%
unpow299.6%
associate-*l*99.6%
Simplified99.6%
if 0.00224999999999999983 < eps Initial program 53.2%
Taylor expanded in x around 0 57.5%
Final simplification77.5%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 eps)) (sin (* 0.5 (- eps (* -2.0 x)))))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * eps)) * sin((0.5 * (eps - (-2.0 * x)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((0.5d0 * eps)) * sin((0.5d0 * (eps - ((-2.0d0) * x)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * eps)) * Math.sin((0.5 * (eps - (-2.0 * x)))));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * eps)) * math.sin((0.5 * (eps - (-2.0 * x)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(Float64(0.5 * Float64(eps - Float64(-2.0 * x)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * eps)) * sin((0.5 * (eps - (-2.0 * x))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps - N[(-2.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right)\right)
\end{array}
Initial program 41.6%
diff-cos48.6%
div-inv48.6%
metadata-eval48.6%
div-inv48.6%
+-commutative48.6%
metadata-eval48.6%
Applied egg-rr48.6%
*-commutative48.6%
+-commutative48.6%
associate--l+77.2%
*-commutative77.2%
associate-+r+77.7%
+-commutative77.7%
Simplified77.7%
Taylor expanded in x around -inf 77.7%
Final simplification77.7%
(FPCore (x eps) :precision binary64 (if (or (<= x -2.35e-49) (not (<= x 8.5e-22))) (* eps (- (sin x))) (* -2.0 (pow (sin (* 0.5 eps)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -2.35e-49) || !(x <= 8.5e-22)) {
tmp = eps * -sin(x);
} else {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-2.35d-49)) .or. (.not. (x <= 8.5d-22))) then
tmp = eps * -sin(x)
else
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -2.35e-49) || !(x <= 8.5e-22)) {
tmp = eps * -Math.sin(x);
} else {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -2.35e-49) or not (x <= 8.5e-22): tmp = eps * -math.sin(x) else: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -2.35e-49) || !(x <= 8.5e-22)) tmp = Float64(eps * Float64(-sin(x))); else tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -2.35e-49) || ~((x <= 8.5e-22))) tmp = eps * -sin(x); else tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -2.35e-49], N[Not[LessEqual[x, 8.5e-22]], $MachinePrecision]], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.35 \cdot 10^{-49} \lor \neg \left(x \leq 8.5 \cdot 10^{-22}\right):\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\end{array}
\end{array}
if x < -2.35000000000000011e-49 or 8.5000000000000001e-22 < x Initial program 7.0%
Taylor expanded in eps around 0 51.9%
associate-*r*51.9%
mul-1-neg51.9%
Simplified51.9%
if -2.35000000000000011e-49 < x < 8.5000000000000001e-22Initial program 80.3%
diff-cos94.4%
div-inv94.4%
metadata-eval94.4%
div-inv94.4%
+-commutative94.4%
metadata-eval94.4%
Applied egg-rr94.4%
*-commutative94.4%
+-commutative94.4%
associate--l+99.5%
*-commutative99.5%
associate-+r+99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in x around 0 93.3%
Final simplification71.5%
(FPCore (x eps) :precision binary64 (if (<= eps -3.9e-7) (+ -1.0 (cos eps)) (if (<= eps 4e-7) (* eps (- (sin x))) (- (cos eps) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -3.9e-7) {
tmp = -1.0 + cos(eps);
} else if (eps <= 4e-7) {
tmp = eps * -sin(x);
} else {
tmp = cos(eps) - cos(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-3.9d-7)) then
tmp = (-1.0d0) + cos(eps)
else if (eps <= 4d-7) then
tmp = eps * -sin(x)
else
tmp = cos(eps) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -3.9e-7) {
tmp = -1.0 + Math.cos(eps);
} else if (eps <= 4e-7) {
tmp = eps * -Math.sin(x);
} else {
tmp = Math.cos(eps) - Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -3.9e-7: tmp = -1.0 + math.cos(eps) elif eps <= 4e-7: tmp = eps * -math.sin(x) else: tmp = math.cos(eps) - math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -3.9e-7) tmp = Float64(-1.0 + cos(eps)); elseif (eps <= 4e-7) tmp = Float64(eps * Float64(-sin(x))); else tmp = Float64(cos(eps) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -3.9e-7) tmp = -1.0 + cos(eps); elseif (eps <= 4e-7) tmp = eps * -sin(x); else tmp = cos(eps) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -3.9e-7], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4e-7], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.9 \cdot 10^{-7}:\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 4 \cdot 10^{-7}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\end{array}
\end{array}
if eps < -3.90000000000000025e-7Initial program 54.5%
Taylor expanded in x around 0 57.3%
if -3.90000000000000025e-7 < eps < 3.9999999999999998e-7Initial program 28.0%
Taylor expanded in eps around 0 86.1%
associate-*r*86.1%
mul-1-neg86.1%
Simplified86.1%
if 3.9999999999999998e-7 < eps Initial program 53.2%
Taylor expanded in x around 0 57.4%
Final simplification70.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (* -0.5 (* eps eps))))
(if (<= eps -0.000185)
t_0
(if (<= eps -1.95e-116)
t_1
(if (<= eps 3.1e-105) (* eps (- x)) (if (<= eps 0.000135) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = -0.5 * (eps * eps);
double tmp;
if (eps <= -0.000185) {
tmp = t_0;
} else if (eps <= -1.95e-116) {
tmp = t_1;
} else if (eps <= 3.1e-105) {
tmp = eps * -x;
} else if (eps <= 0.000135) {
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 * eps)
if (eps <= (-0.000185d0)) then
tmp = t_0
else if (eps <= (-1.95d-116)) then
tmp = t_1
else if (eps <= 3.1d-105) then
tmp = eps * -x
else if (eps <= 0.000135d0) 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 * (eps * eps);
double tmp;
if (eps <= -0.000185) {
tmp = t_0;
} else if (eps <= -1.95e-116) {
tmp = t_1;
} else if (eps <= 3.1e-105) {
tmp = eps * -x;
} else if (eps <= 0.000135) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) t_1 = -0.5 * (eps * eps) tmp = 0 if eps <= -0.000185: tmp = t_0 elif eps <= -1.95e-116: tmp = t_1 elif eps <= 3.1e-105: tmp = eps * -x elif eps <= 0.000135: 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 * Float64(eps * eps)) tmp = 0.0 if (eps <= -0.000185) tmp = t_0; elseif (eps <= -1.95e-116) tmp = t_1; elseif (eps <= 3.1e-105) tmp = Float64(eps * Float64(-x)); elseif (eps <= 0.000135) 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 * eps); tmp = 0.0; if (eps <= -0.000185) tmp = t_0; elseif (eps <= -1.95e-116) tmp = t_1; elseif (eps <= 3.1e-105) tmp = eps * -x; elseif (eps <= 0.000135) 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[(eps * eps), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.000185], t$95$0, If[LessEqual[eps, -1.95e-116], t$95$1, If[LessEqual[eps, 3.1e-105], N[(eps * (-x)), $MachinePrecision], If[LessEqual[eps, 0.000135], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := -0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\mathbf{if}\;\varepsilon \leq -0.000185:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -1.95 \cdot 10^{-116}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 3.1 \cdot 10^{-105}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{elif}\;\varepsilon \leq 0.000135:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.85e-4 or 1.35000000000000002e-4 < eps Initial program 53.8%
Taylor expanded in x around 0 56.4%
if -1.85e-4 < eps < -1.95e-116 or 3.10000000000000014e-105 < eps < 1.35000000000000002e-4Initial program 5.1%
Taylor expanded in x around 0 5.1%
Taylor expanded in eps around 0 41.7%
*-commutative41.7%
unpow241.7%
Simplified41.7%
if -1.95e-116 < eps < 3.10000000000000014e-105Initial program 39.9%
diff-cos41.0%
div-inv41.0%
metadata-eval41.0%
div-inv41.0%
+-commutative41.0%
metadata-eval41.0%
Applied egg-rr41.0%
*-commutative41.0%
+-commutative41.0%
associate--l+99.8%
*-commutative99.8%
associate-+r+99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in eps around 0 98.7%
mul-1-neg98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
Simplified98.7%
Taylor expanded in x around 0 48.4%
mul-1-neg48.4%
distribute-rgt-neg-in48.4%
Simplified48.4%
Final simplification51.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4e-5) (not (<= eps 1.4e-6))) (+ -1.0 (cos eps)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4e-5) || !(eps <= 1.4e-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 <= (-4d-5)) .or. (.not. (eps <= 1.4d-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 <= -4e-5) || !(eps <= 1.4e-6)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4e-5) or not (eps <= 1.4e-6): tmp = -1.0 + math.cos(eps) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -4e-5) || !(eps <= 1.4e-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 <= -4e-5) || ~((eps <= 1.4e-6))) tmp = -1.0 + cos(eps); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4e-5], N[Not[LessEqual[eps, 1.4e-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 -4 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 1.4 \cdot 10^{-6}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -4.00000000000000033e-5 or 1.39999999999999994e-6 < eps Initial program 53.8%
Taylor expanded in x around 0 56.4%
if -4.00000000000000033e-5 < eps < 1.39999999999999994e-6Initial program 28.0%
Taylor expanded in eps around 0 86.1%
associate-*r*86.1%
mul-1-neg86.1%
Simplified86.1%
Final simplification70.4%
(FPCore (x eps) :precision binary64 (if (or (<= x -9.2e-107) (not (<= x 3.9e-91))) (* eps (- x)) (* -0.5 (* eps eps))))
double code(double x, double eps) {
double tmp;
if ((x <= -9.2e-107) || !(x <= 3.9e-91)) {
tmp = eps * -x;
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-9.2d-107)) .or. (.not. (x <= 3.9d-91))) then
tmp = eps * -x
else
tmp = (-0.5d0) * (eps * eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -9.2e-107) || !(x <= 3.9e-91)) {
tmp = eps * -x;
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -9.2e-107) or not (x <= 3.9e-91): tmp = eps * -x else: tmp = -0.5 * (eps * eps) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -9.2e-107) || !(x <= 3.9e-91)) tmp = Float64(eps * Float64(-x)); else tmp = Float64(-0.5 * Float64(eps * eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -9.2e-107) || ~((x <= 3.9e-91))) tmp = eps * -x; else tmp = -0.5 * (eps * eps); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -9.2e-107], N[Not[LessEqual[x, 3.9e-91]], $MachinePrecision]], N[(eps * (-x)), $MachinePrecision], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.2 \cdot 10^{-107} \lor \neg \left(x \leq 3.9 \cdot 10^{-91}\right):\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\end{array}
\end{array}
if x < -9.20000000000000014e-107 or 3.89999999999999994e-91 < x Initial program 16.3%
diff-cos17.9%
div-inv17.9%
metadata-eval17.9%
div-inv17.9%
+-commutative17.9%
metadata-eval17.9%
Applied egg-rr17.9%
*-commutative17.9%
+-commutative17.9%
associate--l+63.6%
*-commutative63.6%
associate-+r+64.4%
+-commutative64.4%
Simplified64.4%
Taylor expanded in eps around 0 48.6%
mul-1-neg48.6%
*-commutative48.6%
distribute-rgt-neg-in48.6%
Simplified48.6%
Taylor expanded in x around 0 11.1%
mul-1-neg11.1%
distribute-rgt-neg-in11.1%
Simplified11.1%
if -9.20000000000000014e-107 < x < 3.89999999999999994e-91Initial program 83.2%
Taylor expanded in x around 0 83.2%
Taylor expanded in eps around 0 48.3%
*-commutative48.3%
unpow248.3%
Simplified48.3%
Final simplification25.2%
(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 41.6%
diff-cos48.6%
div-inv48.6%
metadata-eval48.6%
div-inv48.6%
+-commutative48.6%
metadata-eval48.6%
Applied egg-rr48.6%
*-commutative48.6%
+-commutative48.6%
associate--l+77.2%
*-commutative77.2%
associate-+r+77.7%
+-commutative77.7%
Simplified77.7%
Taylor expanded in eps around 0 42.6%
mul-1-neg42.6%
*-commutative42.6%
distribute-rgt-neg-in42.6%
Simplified42.6%
Taylor expanded in x around 0 19.3%
mul-1-neg19.3%
distribute-rgt-neg-in19.3%
Simplified19.3%
Final simplification19.3%
herbie shell --seed 2023218
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))