
(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 (* 0.5 eps)))) (* -2.0 (* t_0 (fma (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 * fma(sin(x), cos((0.5 * eps)), (t_0 * cos(x))));
}
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * fma(sin(x), cos(Float64(0.5 * eps)), Float64(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[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $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 \mathsf{fma}\left(\sin x, \cos \left(0.5 \cdot \varepsilon\right), t_0 \cdot \cos x\right)\right)
\end{array}
\end{array}
Initial program 37.1%
diff-cos43.0%
div-inv43.0%
metadata-eval43.0%
div-inv43.0%
+-commutative43.0%
metadata-eval43.0%
Applied egg-rr43.0%
*-commutative43.0%
+-commutative43.0%
associate--l+77.7%
*-commutative77.7%
associate-+r+78.0%
+-commutative78.0%
Simplified78.0%
distribute-lft-in78.0%
sin-sum99.4%
Applied egg-rr99.4%
+-commutative99.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%
+-commutative99.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 (fma (cos x) t_0 (* (sin x) (cos (* eps -0.5))))))))
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((eps * -0.5)))));
}
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(eps * -0.5)))))) 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[(eps * -0.5), $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(\varepsilon \cdot -0.5\right)\right)\right)
\end{array}
\end{array}
Initial program 37.1%
diff-cos43.0%
div-inv43.0%
metadata-eval43.0%
div-inv43.0%
+-commutative43.0%
metadata-eval43.0%
Applied egg-rr43.0%
*-commutative43.0%
+-commutative43.0%
associate--l+77.7%
*-commutative77.7%
associate-+r+78.0%
+-commutative78.0%
Simplified78.0%
distribute-lft-in78.0%
sin-sum99.4%
Applied egg-rr99.4%
+-commutative99.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%
+-commutative99.4%
fma-def99.5%
*-commutative99.5%
fma-def99.4%
+-commutative99.4%
fma-def99.4%
metadata-eval99.4%
associate-*r*99.4%
mul-1-neg99.4%
distribute-rgt-neg-out99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
cos-neg99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (+ (* t_0 (cos x)) (* (sin x) (cos (* 0.5 eps))))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * ((t_0 * cos(x)) + (sin(x) * cos((0.5 * eps)))));
}
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 * ((t_0 * cos(x)) + (sin(x) * cos((0.5d0 * eps)))))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
return -2.0 * (t_0 * ((t_0 * Math.cos(x)) + (Math.sin(x) * Math.cos((0.5 * eps)))));
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) return -2.0 * (t_0 * ((t_0 * math.cos(x)) + (math.sin(x) * math.cos((0.5 * eps)))))
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * Float64(Float64(t_0 * cos(x)) + Float64(sin(x) * cos(Float64(0.5 * eps)))))) end
function tmp = code(x, eps) t_0 = sin((0.5 * eps)); tmp = -2.0 * (t_0 * ((t_0 * cos(x)) + (sin(x) * cos((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[(t$95$0 * N[Cos[x], $MachinePrecision]), $MachinePrecision] + 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 \left(t_0 \cdot \cos x + \sin x \cdot \cos \left(0.5 \cdot \varepsilon\right)\right)\right)
\end{array}
\end{array}
Initial program 37.1%
diff-cos43.0%
div-inv43.0%
metadata-eval43.0%
div-inv43.0%
+-commutative43.0%
metadata-eval43.0%
Applied egg-rr43.0%
*-commutative43.0%
+-commutative43.0%
associate--l+77.7%
*-commutative77.7%
associate-+r+78.0%
+-commutative78.0%
Simplified78.0%
distribute-lft-in78.0%
sin-sum99.4%
Applied egg-rr99.4%
+-commutative99.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 (if (or (<= x -2.5e-8) (not (<= x 1.25e-39))) (- (* (cos x) (+ -1.0 (cos eps))) (* (sin x) (sin eps))) (* -2.0 (* (sin (* 0.5 eps)) (sin (+ (* 0.5 eps) x))))))
double code(double x, double eps) {
double tmp;
if ((x <= -2.5e-8) || !(x <= 1.25e-39)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(x) * sin(eps));
} else {
tmp = -2.0 * (sin((0.5 * eps)) * sin(((0.5 * eps) + x)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-2.5d-8)) .or. (.not. (x <= 1.25d-39))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(x) * sin(eps))
else
tmp = (-2.0d0) * (sin((0.5d0 * eps)) * sin(((0.5d0 * eps) + x)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -2.5e-8) || !(x <= 1.25e-39)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(x) * Math.sin(eps));
} else {
tmp = -2.0 * (Math.sin((0.5 * eps)) * Math.sin(((0.5 * eps) + x)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -2.5e-8) or not (x <= 1.25e-39): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(x) * math.sin(eps)) else: tmp = -2.0 * (math.sin((0.5 * eps)) * math.sin(((0.5 * eps) + x))) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -2.5e-8) || !(x <= 1.25e-39)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(x) * sin(eps))); else tmp = Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(Float64(Float64(0.5 * eps) + x)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -2.5e-8) || ~((x <= 1.25e-39))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(x) * sin(eps)); else tmp = -2.0 * (sin((0.5 * eps)) * sin(((0.5 * eps) + x))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -2.5e-8], N[Not[LessEqual[x, 1.25e-39]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(N[(0.5 * eps), $MachinePrecision] + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-8} \lor \neg \left(x \leq 1.25 \cdot 10^{-39}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin x \cdot \sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \varepsilon + x\right)\right)\\
\end{array}
\end{array}
if x < -2.4999999999999999e-8 or 1.25e-39 < x Initial program 9.4%
cos-sum48.7%
cancel-sign-sub-inv48.7%
fma-def48.7%
Applied egg-rr48.7%
Taylor expanded in x around inf 48.7%
neg-mul-148.7%
distribute-lft-neg-in48.7%
associate--l+99.0%
*-commutative99.0%
+-commutative99.0%
distribute-lft-neg-in99.0%
unsub-neg99.0%
*-rgt-identity99.0%
distribute-lft-out--99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
if -2.4999999999999999e-8 < x < 1.25e-39Initial program 73.9%
diff-cos89.2%
div-inv89.2%
metadata-eval89.2%
div-inv89.2%
+-commutative89.2%
metadata-eval89.2%
Applied egg-rr89.2%
*-commutative89.2%
+-commutative89.2%
associate--l+99.7%
*-commutative99.7%
associate-+r+99.7%
+-commutative99.7%
Simplified99.7%
distribute-lft-in99.7%
sin-sum99.7%
Applied egg-rr99.7%
+-commutative99.7%
*-commutative99.7%
count-299.7%
*-commutative99.7%
count-299.7%
*-commutative99.7%
count-299.7%
*-commutative99.7%
count-299.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in eps around inf 99.7%
+-commutative99.7%
sin-sum99.7%
Applied egg-rr99.7%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -5e-16) (* (tan (/ eps 2.0)) (- (sin eps))) (* -2.0 (* (sin (* 0.5 eps)) (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -5e-16) {
tmp = tan((eps / 2.0)) * -sin(eps);
} else {
tmp = -2.0 * (sin((0.5 * eps)) * sin(x));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((cos((eps + x)) - cos(x)) <= (-5d-16)) then
tmp = tan((eps / 2.0d0)) * -sin(eps)
else
tmp = (-2.0d0) * (sin((0.5d0 * eps)) * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -5e-16) {
tmp = Math.tan((eps / 2.0)) * -Math.sin(eps);
} else {
tmp = -2.0 * (Math.sin((0.5 * eps)) * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -5e-16: tmp = math.tan((eps / 2.0)) * -math.sin(eps) else: tmp = -2.0 * (math.sin((0.5 * eps)) * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -5e-16) tmp = Float64(tan(Float64(eps / 2.0)) * Float64(-sin(eps))); else tmp = Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -5e-16) tmp = tan((eps / 2.0)) * -sin(eps); else tmp = -2.0 * (sin((0.5 * eps)) * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -5e-16], N[(N[Tan[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision], N[(-2.0 * N[(N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -5 \cdot 10^{-16}:\\
\;\;\;\;\tan \left(\frac{\varepsilon}{2}\right) \cdot \left(-\sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -5.0000000000000004e-16Initial program 78.2%
Taylor expanded in x around 0 78.4%
flip--78.2%
metadata-eval78.2%
sub-1-cos80.4%
pow180.4%
pow180.4%
pow-prod-up80.4%
metadata-eval80.4%
Applied egg-rr80.4%
distribute-frac-neg80.4%
/-rgt-identity80.4%
associate-/r*80.4%
unpow280.4%
times-frac80.7%
+-commutative80.7%
hang-0p-tan81.0%
/-rgt-identity81.0%
Simplified81.0%
if -5.0000000000000004e-16 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 18.8%
diff-cos26.4%
div-inv26.4%
metadata-eval26.4%
div-inv26.4%
+-commutative26.4%
metadata-eval26.4%
Applied egg-rr26.4%
*-commutative26.4%
+-commutative26.4%
associate--l+76.5%
*-commutative76.5%
associate-+r+76.9%
+-commutative76.9%
Simplified76.9%
distribute-lft-in76.9%
sin-sum99.5%
Applied egg-rr99.5%
+-commutative99.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%
+-commutative99.5%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in eps around 0 68.8%
Final simplification72.6%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -5e-16) (* (tan (/ eps 2.0)) (- (sin eps))) (log1p (- (* eps (sin x))))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -5e-16) {
tmp = tan((eps / 2.0)) * -sin(eps);
} else {
tmp = log1p(-(eps * sin(x)));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -5e-16) {
tmp = Math.tan((eps / 2.0)) * -Math.sin(eps);
} else {
tmp = Math.log1p(-(eps * Math.sin(x)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -5e-16: tmp = math.tan((eps / 2.0)) * -math.sin(eps) else: tmp = math.log1p(-(eps * math.sin(x))) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -5e-16) tmp = Float64(tan(Float64(eps / 2.0)) * Float64(-sin(eps))); else tmp = log1p(Float64(-Float64(eps * sin(x)))); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -5e-16], N[(N[Tan[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision], N[Log[1 + (-N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -5 \cdot 10^{-16}:\\
\;\;\;\;\tan \left(\frac{\varepsilon}{2}\right) \cdot \left(-\sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(-\varepsilon \cdot \sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -5.0000000000000004e-16Initial program 78.2%
Taylor expanded in x around 0 78.4%
flip--78.2%
metadata-eval78.2%
sub-1-cos80.4%
pow180.4%
pow180.4%
pow-prod-up80.4%
metadata-eval80.4%
Applied egg-rr80.4%
distribute-frac-neg80.4%
/-rgt-identity80.4%
associate-/r*80.4%
unpow280.4%
times-frac80.7%
+-commutative80.7%
hang-0p-tan81.0%
/-rgt-identity81.0%
Simplified81.0%
if -5.0000000000000004e-16 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 18.8%
log1p-expm1-u18.8%
Applied egg-rr18.8%
Taylor expanded in eps around 0 67.1%
mul-1-neg67.1%
*-commutative67.1%
distribute-rgt-neg-in67.1%
Simplified67.1%
Final simplification71.4%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -5e-16) (- (cos eps) (cos x)) (log1p (- (* eps (sin x))))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -5e-16) {
tmp = cos(eps) - cos(x);
} else {
tmp = log1p(-(eps * sin(x)));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -5e-16) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = Math.log1p(-(eps * Math.sin(x)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -5e-16: tmp = math.cos(eps) - math.cos(x) else: tmp = math.log1p(-(eps * math.sin(x))) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -5e-16) tmp = Float64(cos(eps) - cos(x)); else tmp = log1p(Float64(-Float64(eps * sin(x)))); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -5e-16], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[Log[1 + (-N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -5 \cdot 10^{-16}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(-\varepsilon \cdot \sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -5.0000000000000004e-16Initial program 78.2%
Taylor expanded in x around 0 78.6%
if -5.0000000000000004e-16 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 18.8%
log1p-expm1-u18.8%
Applied egg-rr18.8%
Taylor expanded in eps around 0 67.1%
mul-1-neg67.1%
*-commutative67.1%
distribute-rgt-neg-in67.1%
Simplified67.1%
Final simplification70.6%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 eps)) (sin (+ (* 0.5 eps) x)))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * eps)) * sin(((0.5 * eps) + 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) + x)))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * eps)) * Math.sin(((0.5 * eps) + x)));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * eps)) * math.sin(((0.5 * eps) + x)))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(Float64(Float64(0.5 * eps) + x)))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * eps)) * sin(((0.5 * eps) + x))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(N[(0.5 * eps), $MachinePrecision] + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \varepsilon + x\right)\right)
\end{array}
Initial program 37.1%
diff-cos43.0%
div-inv43.0%
metadata-eval43.0%
div-inv43.0%
+-commutative43.0%
metadata-eval43.0%
Applied egg-rr43.0%
*-commutative43.0%
+-commutative43.0%
associate--l+77.7%
*-commutative77.7%
associate-+r+78.0%
+-commutative78.0%
Simplified78.0%
distribute-lft-in78.0%
sin-sum99.4%
Applied egg-rr99.4%
+-commutative99.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%
+-commutative99.4%
sin-sum78.0%
Applied egg-rr78.0%
Final simplification78.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.2e-8) (not (<= eps 6.4e-7))) (- (cos eps) (cos x)) (- (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.2e-8) || !(eps <= 6.4e-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.2d-8)) .or. (.not. (eps <= 6.4d-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.2e-8) || !(eps <= 6.4e-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.2e-8) or not (eps <= 6.4e-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.2e-8) || !(eps <= 6.4e-7)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(-Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -4.2e-8) || ~((eps <= 6.4e-7))) tmp = cos(eps) - cos(x); else tmp = -(eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.2e-8], N[Not[LessEqual[eps, 6.4e-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.2 \cdot 10^{-8} \lor \neg \left(\varepsilon \leq 6.4 \cdot 10^{-7}\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-\varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -4.19999999999999989e-8 or 6.4000000000000001e-7 < eps Initial program 52.7%
Taylor expanded in x around 0 54.5%
if -4.19999999999999989e-8 < eps < 6.4000000000000001e-7Initial program 22.4%
Taylor expanded in eps around 0 88.3%
associate-*r*88.3%
mul-1-neg88.3%
Simplified88.3%
Final simplification71.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))))
(if (<= eps -0.00016)
t_0
(if (<= eps -3.8e-175)
(* -0.5 (* eps eps))
(if (<= eps 900.0) (- (* eps x)) t_0)))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double tmp;
if (eps <= -0.00016) {
tmp = t_0;
} else if (eps <= -3.8e-175) {
tmp = -0.5 * (eps * eps);
} else if (eps <= 900.0) {
tmp = -(eps * x);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = (-1.0d0) + cos(eps)
if (eps <= (-0.00016d0)) then
tmp = t_0
else if (eps <= (-3.8d-175)) then
tmp = (-0.5d0) * (eps * eps)
else if (eps <= 900.0d0) then
tmp = -(eps * x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = -1.0 + Math.cos(eps);
double tmp;
if (eps <= -0.00016) {
tmp = t_0;
} else if (eps <= -3.8e-175) {
tmp = -0.5 * (eps * eps);
} else if (eps <= 900.0) {
tmp = -(eps * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) tmp = 0 if eps <= -0.00016: tmp = t_0 elif eps <= -3.8e-175: tmp = -0.5 * (eps * eps) elif eps <= 900.0: tmp = -(eps * x) else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) tmp = 0.0 if (eps <= -0.00016) tmp = t_0; elseif (eps <= -3.8e-175) tmp = Float64(-0.5 * Float64(eps * eps)); elseif (eps <= 900.0) tmp = Float64(-Float64(eps * x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = -1.0 + cos(eps); tmp = 0.0; if (eps <= -0.00016) tmp = t_0; elseif (eps <= -3.8e-175) tmp = -0.5 * (eps * eps); elseif (eps <= 900.0) tmp = -(eps * x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00016], t$95$0, If[LessEqual[eps, -3.8e-175], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 900.0], (-N[(eps * x), $MachinePrecision]), t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.00016:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -3.8 \cdot 10^{-175}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 900:\\
\;\;\;\;-\varepsilon \cdot x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.60000000000000013e-4 or 900 < eps Initial program 53.5%
Taylor expanded in x around 0 53.4%
if -1.60000000000000013e-4 < eps < -3.8e-175Initial program 9.8%
Taylor expanded in x around 0 9.8%
Taylor expanded in eps around 0 33.6%
*-commutative33.6%
unpow233.6%
Simplified33.6%
if -3.8e-175 < eps < 900Initial program 28.3%
Taylor expanded in eps around 0 93.0%
associate-*r*93.0%
mul-1-neg93.0%
Simplified93.0%
Taylor expanded in x around 0 41.3%
associate-*r*41.3%
neg-mul-141.3%
Simplified41.3%
Final simplification45.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.5e-8) (not (<= eps 900.0))) (+ -1.0 (cos eps)) (- (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.5e-8) || !(eps <= 900.0)) {
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 <= (-4.5d-8)) .or. (.not. (eps <= 900.0d0))) 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 <= -4.5e-8) || !(eps <= 900.0)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = -(eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4.5e-8) or not (eps <= 900.0): tmp = -1.0 + math.cos(eps) else: tmp = -(eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -4.5e-8) || !(eps <= 900.0)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(-Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -4.5e-8) || ~((eps <= 900.0))) tmp = -1.0 + cos(eps); else tmp = -(eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.5e-8], N[Not[LessEqual[eps, 900.0]], $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.5 \cdot 10^{-8} \lor \neg \left(\varepsilon \leq 900\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-\varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -4.49999999999999993e-8 or 900 < eps Initial program 53.1%
Taylor expanded in x around 0 53.1%
if -4.49999999999999993e-8 < eps < 900Initial program 22.3%
Taylor expanded in eps around 0 87.7%
associate-*r*87.7%
mul-1-neg87.7%
Simplified87.7%
Final simplification71.1%
(FPCore (x eps) :precision binary64 (if (or (<= x -1.85e-93) (not (<= x 8e-93))) (- (* eps x)) (* -0.5 (* eps eps))))
double code(double x, double eps) {
double tmp;
if ((x <= -1.85e-93) || !(x <= 8e-93)) {
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 <= (-1.85d-93)) .or. (.not. (x <= 8d-93))) 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 <= -1.85e-93) || !(x <= 8e-93)) {
tmp = -(eps * x);
} else {
tmp = -0.5 * (eps * eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -1.85e-93) or not (x <= 8e-93): tmp = -(eps * x) else: tmp = -0.5 * (eps * eps) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -1.85e-93) || !(x <= 8e-93)) tmp = Float64(-Float64(eps * x)); else tmp = Float64(-0.5 * Float64(eps * eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -1.85e-93) || ~((x <= 8e-93))) tmp = -(eps * x); else tmp = -0.5 * (eps * eps); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -1.85e-93], N[Not[LessEqual[x, 8e-93]], $MachinePrecision]], (-N[(eps * x), $MachinePrecision]), N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{-93} \lor \neg \left(x \leq 8 \cdot 10^{-93}\right):\\
\;\;\;\;-\varepsilon \cdot x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\end{array}
\end{array}
if x < -1.85000000000000001e-93 or 7.9999999999999992e-93 < x Initial program 20.1%
Taylor expanded in eps around 0 53.0%
associate-*r*53.0%
mul-1-neg53.0%
Simplified53.0%
Taylor expanded in x around 0 12.3%
associate-*r*12.3%
neg-mul-112.3%
Simplified12.3%
if -1.85000000000000001e-93 < x < 7.9999999999999992e-93Initial program 76.7%
Taylor expanded in x around 0 76.7%
Taylor expanded in eps around 0 52.4%
*-commutative52.4%
unpow252.4%
Simplified52.4%
Final simplification24.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(-Float64(eps * x)) end
function tmp = code(x, eps) tmp = -(eps * x); end
code[x_, eps_] := (-N[(eps * x), $MachinePrecision])
\begin{array}{l}
\\
-\varepsilon \cdot x
\end{array}
Initial program 37.1%
Taylor expanded in eps around 0 47.4%
associate-*r*47.4%
mul-1-neg47.4%
Simplified47.4%
Taylor expanded in x around 0 19.0%
associate-*r*19.0%
neg-mul-119.0%
Simplified19.0%
Final simplification19.0%
herbie shell --seed 2023222
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))