
(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 (* (cos x) (+ -1.0 (cos eps)))))
(if (<= eps -2.35e-5)
(- t_0 (* (sin eps) (sin x)))
(if (<= eps 2.95e-5)
(* (+ (sin x) (* 0.5 (* eps (cos x)))) (* -2.0 (sin (* eps 0.5))))
(fma (sin eps) (- (sin x)) t_0)))))
double code(double x, double eps) {
double t_0 = cos(x) * (-1.0 + cos(eps));
double tmp;
if (eps <= -2.35e-5) {
tmp = t_0 - (sin(eps) * sin(x));
} else if (eps <= 2.95e-5) {
tmp = (sin(x) + (0.5 * (eps * cos(x)))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = fma(sin(eps), -sin(x), t_0);
}
return tmp;
}
function code(x, eps) t_0 = Float64(cos(x) * Float64(-1.0 + cos(eps))) tmp = 0.0 if (eps <= -2.35e-5) tmp = Float64(t_0 - Float64(sin(eps) * sin(x))); elseif (eps <= 2.95e-5) tmp = Float64(Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x)))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = fma(sin(eps), Float64(-sin(x)), t_0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -2.35e-5], N[(t$95$0 - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.95e-5], N[(N[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision]) + t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \left(-1 + \cos \varepsilon\right)\\
\mathbf{if}\;\varepsilon \leq -2.35 \cdot 10^{-5}:\\
\;\;\;\;t_0 - \sin \varepsilon \cdot \sin x\\
\mathbf{elif}\;\varepsilon \leq 2.95 \cdot 10^{-5}:\\
\;\;\;\;\left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin \varepsilon, -\sin x, t_0\right)\\
\end{array}
\end{array}
if eps < -2.34999999999999986e-5Initial program 53.3%
cos-sum97.9%
cancel-sign-sub-inv97.9%
fma-def98.1%
Applied egg-rr98.1%
Taylor expanded in x around inf 97.9%
neg-mul-197.9%
associate--l+98.0%
distribute-rgt-neg-in98.0%
fma-def98.0%
*-lft-identity98.0%
distribute-rgt-out--98.1%
sub-neg98.1%
metadata-eval98.1%
+-commutative98.1%
Simplified98.1%
Taylor expanded in eps around inf 98.2%
if -2.34999999999999986e-5 < eps < 2.9499999999999999e-5Initial program 28.9%
diff-cos43.7%
div-inv43.7%
associate--l+43.7%
metadata-eval43.7%
div-inv43.7%
+-commutative43.7%
associate-+l+43.7%
metadata-eval43.7%
Applied egg-rr43.7%
associate-*r*43.7%
*-commutative43.7%
*-commutative43.7%
+-commutative43.7%
count-243.7%
fma-def43.7%
*-commutative43.7%
associate-+r-43.7%
+-commutative43.7%
associate--l+99.2%
+-inverses99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.6%
if 2.9499999999999999e-5 < eps Initial program 45.9%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
associate--l+98.8%
distribute-rgt-neg-in98.8%
fma-def99.0%
*-lft-identity99.0%
distribute-rgt-out--99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
Simplified99.2%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (fma (sin eps) (- (sin x)) (/ (* (pow (sin eps) 2.0) (cos x)) (- -1.0 (cos eps)))))
double code(double x, double eps) {
return fma(sin(eps), -sin(x), ((pow(sin(eps), 2.0) * cos(x)) / (-1.0 - cos(eps))));
}
function code(x, eps) return fma(sin(eps), Float64(-sin(x)), Float64(Float64((sin(eps) ^ 2.0) * cos(x)) / Float64(-1.0 - cos(eps)))) end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision]) + N[(N[(N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(-1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin \varepsilon, -\sin x, \frac{{\sin \varepsilon}^{2} \cdot \cos x}{-1 - \cos \varepsilon}\right)
\end{array}
Initial program 39.2%
cos-sum64.1%
cancel-sign-sub-inv64.1%
fma-def64.2%
Applied egg-rr64.2%
Taylor expanded in x around inf 64.1%
neg-mul-164.1%
associate--l+91.4%
distribute-rgt-neg-in91.4%
fma-def91.5%
*-lft-identity91.5%
distribute-rgt-out--91.6%
sub-neg91.6%
metadata-eval91.6%
+-commutative91.6%
Simplified91.6%
*-commutative91.6%
flip-+91.2%
associate-*l/91.2%
metadata-eval91.2%
1-sub-cos99.1%
pow299.1%
Applied egg-rr99.1%
Final simplification99.1%
(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.2%
cos-sum64.1%
cancel-sign-sub-inv64.1%
fma-def64.2%
Applied egg-rr64.2%
Taylor expanded in x around inf 64.1%
neg-mul-164.1%
associate--l+91.4%
distribute-rgt-neg-in91.4%
fma-def91.5%
*-lft-identity91.5%
distribute-rgt-out--91.6%
sub-neg91.6%
metadata-eval91.6%
+-commutative91.6%
Simplified91.6%
*-commutative91.6%
flip-+91.2%
associate-*l/91.2%
metadata-eval91.2%
1-sub-cos99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in eps around inf 99.1%
+-commutative99.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.0%
Final simplification99.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.2e-5) (not (<= eps 3.3e-5))) (- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x))) (* (+ (sin x) (* 0.5 (* eps (cos x)))) (* -2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.2e-5) || !(eps <= 3.3e-5)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = (sin(x) + (0.5 * (eps * cos(x)))) * (-2.0 * sin((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 <= (-3.2d-5)) .or. (.not. (eps <= 3.3d-5))) then
tmp = (cos(x) * ((-1.0d0) + cos(eps))) - (sin(eps) * sin(x))
else
tmp = (sin(x) + (0.5d0 * (eps * cos(x)))) * ((-2.0d0) * sin((eps * 0.5d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -3.2e-5) || !(eps <= 3.3e-5)) {
tmp = (Math.cos(x) * (-1.0 + Math.cos(eps))) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = (Math.sin(x) + (0.5 * (eps * Math.cos(x)))) * (-2.0 * Math.sin((eps * 0.5)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.2e-5) or not (eps <= 3.3e-5): tmp = (math.cos(x) * (-1.0 + math.cos(eps))) - (math.sin(eps) * math.sin(x)) else: tmp = (math.sin(x) + (0.5 * (eps * math.cos(x)))) * (-2.0 * math.sin((eps * 0.5))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.2e-5) || !(eps <= 3.3e-5)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(sin(x) + Float64(0.5 * Float64(eps * cos(x)))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -3.2e-5) || ~((eps <= 3.3e-5))) tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x)); else tmp = (sin(x) + (0.5 * (eps * cos(x)))) * (-2.0 * sin((eps * 0.5))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.2e-5], N[Not[LessEqual[eps, 3.3e-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[(N[Sin[x], $MachinePrecision] + N[(0.5 * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.2 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 3.3 \cdot 10^{-5}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(\sin x + 0.5 \cdot \left(\varepsilon \cdot \cos x\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -3.19999999999999986e-5 or 3.3000000000000003e-5 < eps Initial program 49.6%
cos-sum98.3%
cancel-sign-sub-inv98.3%
fma-def98.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 98.3%
neg-mul-198.3%
associate--l+98.4%
distribute-rgt-neg-in98.4%
fma-def98.5%
*-lft-identity98.5%
distribute-rgt-out--98.7%
sub-neg98.7%
metadata-eval98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in eps around inf 98.6%
if -3.19999999999999986e-5 < eps < 3.3000000000000003e-5Initial program 28.9%
diff-cos43.7%
div-inv43.7%
associate--l+43.7%
metadata-eval43.7%
div-inv43.7%
+-commutative43.7%
associate-+l+43.7%
metadata-eval43.7%
Applied egg-rr43.7%
associate-*r*43.7%
*-commutative43.7%
*-commutative43.7%
+-commutative43.7%
count-243.7%
fma-def43.7%
*-commutative43.7%
associate-+r-43.7%
+-commutative43.7%
associate--l+99.2%
+-inverses99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.6%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (<= (- (cos (+ eps x)) (cos x)) -5e-14)
(* -2.0 (pow t_0 2.0))
(* (sin x) (* -2.0 t_0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((cos((eps + x)) - cos(x)) <= -5e-14) {
tmp = -2.0 * pow(t_0, 2.0);
} else {
tmp = sin(x) * (-2.0 * t_0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((eps * 0.5d0))
if ((cos((eps + x)) - cos(x)) <= (-5d-14)) then
tmp = (-2.0d0) * (t_0 ** 2.0d0)
else
tmp = sin(x) * ((-2.0d0) * t_0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -5e-14) {
tmp = -2.0 * Math.pow(t_0, 2.0);
} else {
tmp = Math.sin(x) * (-2.0 * t_0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -5e-14: tmp = -2.0 * math.pow(t_0, 2.0) else: tmp = math.sin(x) * (-2.0 * t_0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -5e-14) tmp = Float64(-2.0 * (t_0 ^ 2.0)); else tmp = Float64(sin(x) * Float64(-2.0 * t_0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -5e-14) tmp = -2.0 * (t_0 ^ 2.0); else tmp = sin(x) * (-2.0 * t_0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -5e-14], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -5 \cdot 10^{-14}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-2 \cdot t_0\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -5.0000000000000002e-14Initial program 70.6%
diff-cos72.3%
div-inv72.3%
associate--l+72.3%
metadata-eval72.3%
div-inv72.3%
+-commutative72.3%
associate-+l+72.3%
metadata-eval72.3%
Applied egg-rr72.3%
associate-*r*72.3%
*-commutative72.3%
*-commutative72.3%
+-commutative72.3%
count-272.3%
fma-def72.3%
*-commutative72.3%
associate-+r-72.3%
+-commutative72.3%
associate--l+72.5%
+-inverses72.5%
Simplified72.5%
Taylor expanded in x around 0 72.4%
if -5.0000000000000002e-14 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 22.8%
diff-cos33.7%
div-inv33.7%
associate--l+33.7%
metadata-eval33.7%
div-inv33.7%
+-commutative33.7%
associate-+l+33.7%
metadata-eval33.7%
Applied egg-rr33.7%
associate-*r*33.7%
*-commutative33.7%
*-commutative33.7%
+-commutative33.7%
count-233.7%
fma-def33.7%
*-commutative33.7%
associate-+r-33.7%
+-commutative33.7%
associate--l+77.1%
+-inverses77.1%
Simplified77.1%
Taylor expanded in eps around 0 66.3%
Final simplification68.4%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -5e-14) (+ -1.0 (cos eps)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -5e-14) {
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 ((cos((eps + x)) - cos(x)) <= (-5d-14)) 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 ((Math.cos((eps + x)) - Math.cos(x)) <= -5e-14) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -5e-14: tmp = -1.0 + math.cos(eps) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -5e-14) 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 ((cos((eps + x)) - cos(x)) <= -5e-14) tmp = -1.0 + cos(eps); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -5e-14], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -5 \cdot 10^{-14}:\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -5.0000000000000002e-14Initial program 70.6%
Taylor expanded in x around 0 70.6%
if -5.0000000000000002e-14 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 22.8%
Taylor expanded in eps around 0 64.8%
mul-1-neg64.8%
*-commutative64.8%
distribute-rgt-neg-in64.8%
Simplified64.8%
Final simplification66.8%
(FPCore (x eps) :precision binary64 (* (* -2.0 (sin (* eps 0.5))) (sin (* 0.5 (fma 2.0 x eps)))))
double code(double x, double eps) {
return (-2.0 * sin((eps * 0.5))) * sin((0.5 * fma(2.0, x, eps)));
}
function code(x, eps) return Float64(Float64(-2.0 * sin(Float64(eps * 0.5))) * sin(Float64(0.5 * fma(2.0, x, eps)))) end
code[x_, eps_] := N[(N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right) \cdot \sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right)
\end{array}
Initial program 39.2%
diff-cos47.0%
div-inv47.0%
associate--l+47.0%
metadata-eval47.0%
div-inv47.0%
+-commutative47.0%
associate-+l+47.0%
metadata-eval47.0%
Applied egg-rr47.0%
associate-*r*47.0%
*-commutative47.0%
*-commutative47.0%
+-commutative47.0%
count-247.0%
fma-def47.0%
*-commutative47.0%
associate-+r-47.0%
+-commutative47.0%
associate--l+75.5%
+-inverses75.5%
Simplified75.5%
Final simplification75.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -9.4e-26) (not (<= eps 1.2e-8))) (* -2.0 (pow (sin (* eps 0.5)) 2.0)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -9.4e-26) || !(eps <= 1.2e-8)) {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
} 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 <= (-9.4d-26)) .or. (.not. (eps <= 1.2d-8))) then
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -9.4e-26) || !(eps <= 1.2e-8)) {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -9.4e-26) or not (eps <= 1.2e-8): tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -9.4e-26) || !(eps <= 1.2e-8)) tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -9.4e-26) || ~((eps <= 1.2e-8))) tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -9.4e-26], N[Not[LessEqual[eps, 1.2e-8]], $MachinePrecision]], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -9.4 \cdot 10^{-26} \lor \neg \left(\varepsilon \leq 1.2 \cdot 10^{-8}\right):\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -9.39999999999999979e-26 or 1.19999999999999999e-8 < eps Initial program 47.4%
diff-cos51.7%
div-inv51.7%
associate--l+51.7%
metadata-eval51.7%
div-inv51.7%
+-commutative51.7%
associate-+l+51.7%
metadata-eval51.7%
Applied egg-rr51.7%
associate-*r*51.7%
*-commutative51.7%
*-commutative51.7%
+-commutative51.7%
count-251.7%
fma-def51.7%
*-commutative51.7%
associate-+r-51.7%
+-commutative51.7%
associate--l+54.6%
+-inverses54.6%
Simplified54.6%
Taylor expanded in x around 0 53.2%
if -9.39999999999999979e-26 < eps < 1.19999999999999999e-8Initial program 30.0%
Taylor expanded in eps around 0 87.6%
mul-1-neg87.6%
*-commutative87.6%
distribute-rgt-neg-in87.6%
Simplified87.6%
Final simplification69.4%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* eps 0.5)) (sin (* 0.5 (+ eps (* x 2.0)))))))
double code(double x, double eps) {
return -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps + (x * 2.0)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((eps * 0.5d0)) * sin((0.5d0 * (eps + (x * 2.0d0)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((eps * 0.5)) * Math.sin((0.5 * (eps + (x * 2.0)))));
}
def code(x, eps): return -2.0 * (math.sin((eps * 0.5)) * math.sin((0.5 * (eps + (x * 2.0)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(eps * 0.5)) * sin(Float64(0.5 * Float64(eps + Float64(x * 2.0)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((eps * 0.5)) * sin((0.5 * (eps + (x * 2.0))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon + x \cdot 2\right)\right)\right)
\end{array}
Initial program 39.2%
log1p-expm1-u39.2%
Applied egg-rr39.2%
log1p-expm1-u39.2%
diff-cos47.0%
div-inv47.0%
+-commutative47.0%
associate--l+75.5%
metadata-eval75.5%
div-inv75.5%
+-commutative75.5%
associate-+l+75.5%
metadata-eval75.5%
Applied egg-rr75.5%
*-commutative75.5%
+-inverses75.5%
*-commutative75.5%
count-275.5%
Simplified75.5%
Final simplification75.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000175) (not (<= eps 0.0125))) (+ -1.0 (cos eps)) (* -0.5 (pow eps 2.0))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000175) || !(eps <= 0.0125)) {
tmp = -1.0 + cos(eps);
} else {
tmp = -0.5 * pow(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 ((eps <= (-0.000175d0)) .or. (.not. (eps <= 0.0125d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = (-0.5d0) * (eps ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.000175) || !(eps <= 0.0125)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = -0.5 * Math.pow(eps, 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000175) or not (eps <= 0.0125): tmp = -1.0 + math.cos(eps) else: tmp = -0.5 * math.pow(eps, 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000175) || !(eps <= 0.0125)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(-0.5 * (eps ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000175) || ~((eps <= 0.0125))) tmp = -1.0 + cos(eps); else tmp = -0.5 * (eps ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000175], N[Not[LessEqual[eps, 0.0125]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000175 \lor \neg \left(\varepsilon \leq 0.0125\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2}\\
\end{array}
\end{array}
if eps < -1.74999999999999998e-4 or 0.012500000000000001 < eps Initial program 49.9%
Taylor expanded in x around 0 51.8%
if -1.74999999999999998e-4 < eps < 0.012500000000000001Initial program 28.7%
Taylor expanded in x around 0 28.8%
Taylor expanded in eps around 0 43.4%
Final simplification47.6%
(FPCore (x eps) :precision binary64 (- 1.0 (cos x)))
double code(double x, double eps) {
return 1.0 - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 1.0d0 - cos(x)
end function
public static double code(double x, double eps) {
return 1.0 - Math.cos(x);
}
def code(x, eps): return 1.0 - math.cos(x)
function code(x, eps) return Float64(1.0 - cos(x)) end
function tmp = code(x, eps) tmp = 1.0 - cos(x); end
code[x_, eps_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \cos x
\end{array}
Initial program 39.2%
Taylor expanded in x around 0 38.1%
mul-1-neg38.1%
unsub-neg38.1%
Simplified38.1%
Taylor expanded in eps around 0 17.6%
Final simplification17.6%
(FPCore (x eps) :precision binary64 (+ -1.0 (cos eps)))
double code(double x, double eps) {
return -1.0 + cos(eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-1.0d0) + cos(eps)
end function
public static double code(double x, double eps) {
return -1.0 + Math.cos(eps);
}
def code(x, eps): return -1.0 + math.cos(eps)
function code(x, eps) return Float64(-1.0 + cos(eps)) end
function tmp = code(x, eps) tmp = -1.0 + cos(eps); end
code[x_, eps_] := N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \cos \varepsilon
\end{array}
Initial program 39.2%
Taylor expanded in x around 0 40.2%
Final simplification40.2%
(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 39.2%
Taylor expanded in x around 0 38.1%
mul-1-neg38.1%
unsub-neg38.1%
Simplified38.1%
Taylor expanded in eps around 0 17.6%
Taylor expanded in x around 0 15.7%
Final simplification15.7%
herbie shell --seed 2024019
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))