
(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 14 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 -0.000175) (not (<= eps 0.00019)))
(fma (cos x) (cos eps) (- (- (cos x)) (* (sin x) (sin eps))))
(*
(+ (* (sin x) (+ (* -0.125 (pow eps 2.0)) 1.0)) (* (cos x) (* eps 0.5)))
(* -2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000175) || !(eps <= 0.00019)) {
tmp = fma(cos(x), cos(eps), (-cos(x) - (sin(x) * sin(eps))));
} else {
tmp = ((sin(x) * ((-0.125 * pow(eps, 2.0)) + 1.0)) + (cos(x) * (eps * 0.5))) * (-2.0 * sin((eps * 0.5)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -0.000175) || !(eps <= 0.00019)) tmp = fma(cos(x), cos(eps), Float64(Float64(-cos(x)) - Float64(sin(x) * sin(eps)))); else tmp = Float64(Float64(Float64(sin(x) * Float64(Float64(-0.125 * (eps ^ 2.0)) + 1.0)) + Float64(cos(x) * Float64(eps * 0.5))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000175], N[Not[LessEqual[eps, 0.00019]], $MachinePrecision]], N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[((-N[Cos[x], $MachinePrecision]) - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(-0.125 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(eps * 0.5), $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 -0.000175 \lor \neg \left(\varepsilon \leq 0.00019\right):\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \left(-\cos x\right) - \sin x \cdot \sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\sin x \cdot \left(-0.125 \cdot {\varepsilon}^{2} + 1\right) + \cos x \cdot \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -1.74999999999999998e-4 or 1.9000000000000001e-4 < eps Initial program 59.7%
sub-neg59.7%
cos-sum98.3%
associate-+l-98.4%
fma-neg98.4%
Applied egg-rr98.4%
sub-neg98.4%
remove-double-neg98.4%
Applied egg-rr98.4%
if -1.74999999999999998e-4 < eps < 1.9000000000000001e-4Initial program 26.3%
diff-cos42.0%
div-inv42.0%
associate--l+42.0%
metadata-eval42.0%
div-inv42.0%
+-commutative42.0%
associate-+l+42.0%
metadata-eval42.0%
Applied egg-rr42.0%
associate-*r*42.0%
*-commutative42.0%
*-commutative42.0%
+-commutative42.0%
count-242.0%
fma-def42.0%
sub-neg42.0%
mul-1-neg42.0%
+-commutative42.0%
associate-+r+99.2%
mul-1-neg99.2%
sub-neg99.2%
+-inverses99.2%
remove-double-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
neg-sub099.2%
mul-1-neg99.2%
remove-double-neg99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.8%
associate-+r+99.8%
associate-*r*99.8%
distribute-rgt1-in99.8%
associate-*r*99.8%
Simplified99.8%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.00021)
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps))))
(if (<= eps 0.00018)
(*
(+ (* (sin x) (+ (* -0.125 (pow eps 2.0)) 1.0)) (* (cos x) (* eps 0.5)))
(* -2.0 (sin (* eps 0.5))))
(- (fma (cos x) (cos eps) (* (sin x) (- (sin eps)))) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.00021) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
} else if (eps <= 0.00018) {
tmp = ((sin(x) * ((-0.125 * pow(eps, 2.0)) + 1.0)) + (cos(x) * (eps * 0.5))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = fma(cos(x), cos(eps), (sin(x) * -sin(eps))) - cos(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.00021) tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(x) * sin(eps)))); elseif (eps <= 0.00018) tmp = Float64(Float64(Float64(sin(x) * Float64(Float64(-0.125 * (eps ^ 2.0)) + 1.0)) + Float64(cos(x) * Float64(eps * 0.5))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = Float64(fma(cos(x), cos(eps), Float64(sin(x) * Float64(-sin(eps)))) - cos(x)); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.00021], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00018], N[(N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(-0.125 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(eps * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00021:\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00018:\\
\;\;\;\;\left(\sin x \cdot \left(-0.125 \cdot {\varepsilon}^{2} + 1\right) + \cos x \cdot \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \sin x \cdot \left(-\sin \varepsilon\right)\right) - \cos x\\
\end{array}
\end{array}
if eps < -2.1000000000000001e-4Initial program 56.1%
sub-neg56.1%
cos-sum98.0%
associate-+l-98.1%
fma-neg98.2%
Applied egg-rr98.2%
Taylor expanded in x around inf 98.1%
if -2.1000000000000001e-4 < eps < 1.80000000000000011e-4Initial program 26.3%
diff-cos42.0%
div-inv42.0%
associate--l+42.0%
metadata-eval42.0%
div-inv42.0%
+-commutative42.0%
associate-+l+42.0%
metadata-eval42.0%
Applied egg-rr42.0%
associate-*r*42.0%
*-commutative42.0%
*-commutative42.0%
+-commutative42.0%
count-242.0%
fma-def42.0%
sub-neg42.0%
mul-1-neg42.0%
+-commutative42.0%
associate-+r+99.2%
mul-1-neg99.2%
sub-neg99.2%
+-inverses99.2%
remove-double-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
neg-sub099.2%
mul-1-neg99.2%
remove-double-neg99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.8%
associate-+r+99.8%
associate-*r*99.8%
distribute-rgt1-in99.8%
associate-*r*99.8%
Simplified99.8%
if 1.80000000000000011e-4 < eps Initial program 63.1%
cos-sum98.7%
cancel-sign-sub-inv98.7%
fma-def98.7%
Applied egg-rr98.7%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00021) (not (<= eps 0.000195)))
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps))))
(*
(+ (* (sin x) (+ (* -0.125 (pow eps 2.0)) 1.0)) (* (cos x) (* eps 0.5)))
(* -2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00021) || !(eps <= 0.000195)) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
} else {
tmp = ((sin(x) * ((-0.125 * pow(eps, 2.0)) + 1.0)) + (cos(x) * (eps * 0.5))) * (-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 <= (-0.00021d0)) .or. (.not. (eps <= 0.000195d0))) then
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)))
else
tmp = ((sin(x) * (((-0.125d0) * (eps ** 2.0d0)) + 1.0d0)) + (cos(x) * (eps * 0.5d0))) * ((-2.0d0) * sin((eps * 0.5d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.00021) || !(eps <= 0.000195)) {
tmp = (Math.cos(x) * Math.cos(eps)) - (Math.cos(x) + (Math.sin(x) * Math.sin(eps)));
} else {
tmp = ((Math.sin(x) * ((-0.125 * Math.pow(eps, 2.0)) + 1.0)) + (Math.cos(x) * (eps * 0.5))) * (-2.0 * Math.sin((eps * 0.5)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00021) or not (eps <= 0.000195): tmp = (math.cos(x) * math.cos(eps)) - (math.cos(x) + (math.sin(x) * math.sin(eps))) else: tmp = ((math.sin(x) * ((-0.125 * math.pow(eps, 2.0)) + 1.0)) + (math.cos(x) * (eps * 0.5))) * (-2.0 * math.sin((eps * 0.5))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00021) || !(eps <= 0.000195)) tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(x) * sin(eps)))); else tmp = Float64(Float64(Float64(sin(x) * Float64(Float64(-0.125 * (eps ^ 2.0)) + 1.0)) + Float64(cos(x) * Float64(eps * 0.5))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00021) || ~((eps <= 0.000195))) tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps))); else tmp = ((sin(x) * ((-0.125 * (eps ^ 2.0)) + 1.0)) + (cos(x) * (eps * 0.5))) * (-2.0 * sin((eps * 0.5))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00021], N[Not[LessEqual[eps, 0.000195]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[x], $MachinePrecision] * N[(N[(-0.125 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(eps * 0.5), $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 -0.00021 \lor \neg \left(\varepsilon \leq 0.000195\right):\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\sin x \cdot \left(-0.125 \cdot {\varepsilon}^{2} + 1\right) + \cos x \cdot \left(\varepsilon \cdot 0.5\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -2.1000000000000001e-4 or 1.94999999999999996e-4 < eps Initial program 59.7%
sub-neg59.7%
cos-sum98.3%
associate-+l-98.4%
fma-neg98.4%
Applied egg-rr98.4%
Taylor expanded in x around inf 98.4%
if -2.1000000000000001e-4 < eps < 1.94999999999999996e-4Initial program 26.3%
diff-cos42.0%
div-inv42.0%
associate--l+42.0%
metadata-eval42.0%
div-inv42.0%
+-commutative42.0%
associate-+l+42.0%
metadata-eval42.0%
Applied egg-rr42.0%
associate-*r*42.0%
*-commutative42.0%
*-commutative42.0%
+-commutative42.0%
count-242.0%
fma-def42.0%
sub-neg42.0%
mul-1-neg42.0%
+-commutative42.0%
associate-+r+99.2%
mul-1-neg99.2%
sub-neg99.2%
+-inverses99.2%
remove-double-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
neg-sub099.2%
mul-1-neg99.2%
remove-double-neg99.2%
Simplified99.2%
Taylor expanded in eps around 0 99.8%
associate-+r+99.8%
associate-*r*99.8%
distribute-rgt1-in99.8%
associate-*r*99.8%
Simplified99.8%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -4e-5) (* -2.0 (pow (sin (* eps 0.5)) 2.0)) (- (* (cos x) (* (pow eps 2.0) -0.5)) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -4e-5) {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
} else {
tmp = (cos(x) * (pow(eps, 2.0) * -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)) <= (-4d-5)) then
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
else
tmp = (cos(x) * ((eps ** 2.0d0) * (-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)) <= -4e-5) {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
} else {
tmp = (Math.cos(x) * (Math.pow(eps, 2.0) * -0.5)) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -4e-5: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) else: tmp = (math.cos(x) * (math.pow(eps, 2.0) * -0.5)) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -4e-5) tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); else tmp = Float64(Float64(cos(x) * Float64((eps ^ 2.0) * -0.5)) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -4e-5) tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); else tmp = (cos(x) * ((eps ^ 2.0) * -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], -4e-5], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[(N[Power[eps, 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -4 \cdot 10^{-5}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left({\varepsilon}^{2} \cdot -0.5\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -4.00000000000000033e-5Initial program 83.8%
diff-cos84.1%
div-inv84.1%
associate--l+84.1%
metadata-eval84.1%
div-inv84.1%
+-commutative84.1%
associate-+l+84.1%
metadata-eval84.1%
Applied egg-rr84.1%
associate-*r*84.1%
*-commutative84.1%
*-commutative84.1%
+-commutative84.1%
count-284.1%
fma-def84.1%
sub-neg84.1%
mul-1-neg84.1%
+-commutative84.1%
associate-+r+84.0%
mul-1-neg84.0%
sub-neg84.0%
+-inverses84.0%
remove-double-neg84.0%
mul-1-neg84.0%
sub-neg84.0%
neg-sub084.0%
mul-1-neg84.0%
remove-double-neg84.0%
Simplified84.0%
Taylor expanded in x around 0 84.5%
if -4.00000000000000033e-5 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 21.1%
Taylor expanded in eps around 0 75.8%
+-commutative75.8%
mul-1-neg75.8%
unsub-neg75.8%
associate-*r*75.8%
*-commutative75.8%
Simplified75.8%
Final simplification78.9%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -4e-5) (* -2.0 (pow (sin (* eps 0.5)) 2.0)) (* eps (- (sin (* 0.5 (fma 2.0 x eps)))))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -4e-5) {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
} else {
tmp = eps * -sin((0.5 * fma(2.0, x, eps)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -4e-5) tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); else tmp = Float64(eps * Float64(-sin(Float64(0.5 * fma(2.0, x, eps))))); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -4e-5], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -4 \cdot 10^{-5}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -4.00000000000000033e-5Initial program 83.8%
diff-cos84.1%
div-inv84.1%
associate--l+84.1%
metadata-eval84.1%
div-inv84.1%
+-commutative84.1%
associate-+l+84.1%
metadata-eval84.1%
Applied egg-rr84.1%
associate-*r*84.1%
*-commutative84.1%
*-commutative84.1%
+-commutative84.1%
count-284.1%
fma-def84.1%
sub-neg84.1%
mul-1-neg84.1%
+-commutative84.1%
associate-+r+84.0%
mul-1-neg84.0%
sub-neg84.0%
+-inverses84.0%
remove-double-neg84.0%
mul-1-neg84.0%
sub-neg84.0%
neg-sub084.0%
mul-1-neg84.0%
remove-double-neg84.0%
Simplified84.0%
Taylor expanded in x around 0 84.5%
if -4.00000000000000033e-5 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 21.1%
diff-cos33.1%
div-inv33.1%
associate--l+33.1%
metadata-eval33.1%
div-inv33.1%
+-commutative33.1%
associate-+l+33.1%
metadata-eval33.1%
Applied egg-rr33.1%
associate-*r*33.1%
*-commutative33.1%
*-commutative33.1%
+-commutative33.1%
count-233.1%
fma-def33.1%
sub-neg33.1%
mul-1-neg33.1%
+-commutative33.1%
associate-+r+76.6%
mul-1-neg76.6%
sub-neg76.6%
+-inverses76.6%
remove-double-neg76.6%
mul-1-neg76.6%
sub-neg76.6%
neg-sub076.6%
mul-1-neg76.6%
remove-double-neg76.6%
Simplified76.6%
add-sqr-sqrt40.2%
sqrt-unprod50.2%
pow250.2%
Applied egg-rr50.2%
unpow250.2%
rem-sqrt-square50.2%
Simplified50.2%
Taylor expanded in eps around 0 48.2%
mul-1-neg48.2%
rem-square-sqrt39.5%
fabs-sqr39.5%
rem-square-sqrt75.2%
distribute-rgt-neg-in75.2%
Simplified75.2%
Final simplification78.5%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- (cos (+ eps x)) (cos x)))) (if (<= t_0 -4e-5) t_0 (- (* eps (sin x))))))
double code(double x, double eps) {
double t_0 = cos((eps + x)) - cos(x);
double tmp;
if (t_0 <= -4e-5) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = cos((eps + x)) - cos(x)
if (t_0 <= (-4d-5)) then
tmp = t_0
else
tmp = -(eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos((eps + x)) - Math.cos(x);
double tmp;
if (t_0 <= -4e-5) {
tmp = t_0;
} else {
tmp = -(eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): t_0 = math.cos((eps + x)) - math.cos(x) tmp = 0 if t_0 <= -4e-5: tmp = t_0 else: tmp = -(eps * math.sin(x)) return tmp
function code(x, eps) t_0 = Float64(cos(Float64(eps + x)) - cos(x)) tmp = 0.0 if (t_0 <= -4e-5) tmp = t_0; else tmp = Float64(-Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos((eps + x)) - cos(x); tmp = 0.0; if (t_0 <= -4e-5) tmp = t_0; else tmp = -(eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -4e-5], t$95$0, (-N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\varepsilon + x\right) - \cos x\\
\mathbf{if}\;t_0 \leq -4 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-\varepsilon \cdot \sin x\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -4.00000000000000033e-5Initial program 83.8%
if -4.00000000000000033e-5 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 21.1%
Taylor expanded in eps around 0 63.7%
mul-1-neg63.7%
*-commutative63.7%
distribute-rgt-neg-in63.7%
Simplified63.7%
Final simplification70.9%
(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 43.6%
diff-cos51.4%
div-inv51.4%
associate--l+51.4%
metadata-eval51.4%
div-inv51.4%
+-commutative51.4%
associate-+l+51.4%
metadata-eval51.4%
Applied egg-rr51.4%
associate-*r*51.4%
*-commutative51.4%
*-commutative51.4%
+-commutative51.4%
count-251.4%
fma-def51.4%
sub-neg51.4%
mul-1-neg51.4%
+-commutative51.4%
associate-+r+79.3%
mul-1-neg79.3%
sub-neg79.3%
+-inverses79.3%
remove-double-neg79.3%
mul-1-neg79.3%
sub-neg79.3%
neg-sub079.3%
mul-1-neg79.3%
remove-double-neg79.3%
Simplified79.3%
Final simplification79.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -4e-11) (not (<= x 1.8e-51)))
(* (sin x) (* -2.0 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 <= -4e-11) || !(x <= 1.8e-51)) {
tmp = sin(x) * (-2.0 * 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 <= (-4d-11)) .or. (.not. (x <= 1.8d-51))) then
tmp = sin(x) * ((-2.0d0) * 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 <= -4e-11) || !(x <= 1.8e-51)) {
tmp = Math.sin(x) * (-2.0 * 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 <= -4e-11) or not (x <= 1.8e-51): tmp = math.sin(x) * (-2.0 * 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 <= -4e-11) || !(x <= 1.8e-51)) tmp = Float64(sin(x) * Float64(-2.0 * 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 <= -4e-11) || ~((x <= 1.8e-51))) tmp = sin(x) * (-2.0 * 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, -4e-11], N[Not[LessEqual[x, 1.8e-51]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * N[(-2.0 * 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 -4 \cdot 10^{-11} \lor \neg \left(x \leq 1.8 \cdot 10^{-51}\right):\\
\;\;\;\;\sin x \cdot \left(-2 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -3.99999999999999976e-11 or 1.8e-51 < x Initial program 9.5%
diff-cos9.5%
div-inv9.5%
associate--l+9.5%
metadata-eval9.5%
div-inv9.5%
+-commutative9.5%
associate-+l+9.5%
metadata-eval9.5%
Applied egg-rr9.5%
associate-*r*9.5%
*-commutative9.5%
*-commutative9.5%
+-commutative9.5%
count-29.5%
fma-def9.5%
sub-neg9.5%
mul-1-neg9.5%
+-commutative9.5%
associate-+r+60.0%
mul-1-neg60.0%
sub-neg60.0%
+-inverses60.0%
remove-double-neg60.0%
mul-1-neg60.0%
sub-neg60.0%
neg-sub060.0%
mul-1-neg60.0%
remove-double-neg60.0%
Simplified60.0%
Taylor expanded in eps around 0 57.4%
if -3.99999999999999976e-11 < x < 1.8e-51Initial program 79.4%
diff-cos95.3%
div-inv95.3%
associate--l+95.3%
metadata-eval95.3%
div-inv95.3%
+-commutative95.3%
associate-+l+95.3%
metadata-eval95.3%
Applied egg-rr95.3%
associate-*r*95.3%
*-commutative95.3%
*-commutative95.3%
+-commutative95.3%
count-295.3%
fma-def95.3%
sub-neg95.3%
mul-1-neg95.3%
+-commutative95.3%
associate-+r+99.5%
mul-1-neg99.5%
sub-neg99.5%
+-inverses99.5%
remove-double-neg99.5%
mul-1-neg99.5%
sub-neg99.5%
neg-sub099.5%
mul-1-neg99.5%
remove-double-neg99.5%
Simplified99.5%
Taylor expanded in x around 0 94.3%
Final simplification75.4%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.023)
(- (cos eps) (cos x))
(if (<= eps 1.75e-47)
(- (* eps (sin x)))
(* -2.0 (pow (sin (* eps 0.5)) 2.0)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.023) {
tmp = cos(eps) - cos(x);
} else if (eps <= 1.75e-47) {
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 (eps <= (-0.023d0)) then
tmp = cos(eps) - cos(x)
else if (eps <= 1.75d-47) 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 (eps <= -0.023) {
tmp = Math.cos(eps) - Math.cos(x);
} else if (eps <= 1.75e-47) {
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 eps <= -0.023: tmp = math.cos(eps) - math.cos(x) elif eps <= 1.75e-47: 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 (eps <= -0.023) tmp = Float64(cos(eps) - cos(x)); elseif (eps <= 1.75e-47) tmp = Float64(-Float64(eps * 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 (eps <= -0.023) tmp = cos(eps) - cos(x); elseif (eps <= 1.75e-47) tmp = -(eps * sin(x)); else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.023], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 1.75e-47], (-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}\;\varepsilon \leq -0.023:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{elif}\;\varepsilon \leq 1.75 \cdot 10^{-47}:\\
\;\;\;\;-\varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if eps < -0.023Initial program 57.0%
Taylor expanded in x around 0 58.8%
if -0.023 < eps < 1.7499999999999999e-47Initial program 27.9%
Taylor expanded in eps around 0 87.4%
mul-1-neg87.4%
*-commutative87.4%
distribute-rgt-neg-in87.4%
Simplified87.4%
if 1.7499999999999999e-47 < eps Initial program 56.1%
diff-cos64.4%
div-inv64.4%
associate--l+64.4%
metadata-eval64.4%
div-inv64.4%
+-commutative64.4%
associate-+l+64.4%
metadata-eval64.4%
Applied egg-rr64.4%
associate-*r*64.4%
*-commutative64.4%
*-commutative64.4%
+-commutative64.4%
count-264.4%
fma-def64.4%
sub-neg64.4%
mul-1-neg64.4%
+-commutative64.4%
associate-+r+68.1%
mul-1-neg68.1%
sub-neg68.1%
+-inverses68.1%
remove-double-neg68.1%
mul-1-neg68.1%
sub-neg68.1%
neg-sub068.1%
mul-1-neg68.1%
remove-double-neg68.1%
Simplified68.1%
Taylor expanded in x around 0 66.4%
Final simplification73.9%
(FPCore (x eps) :precision binary64 (if (<= eps -0.023) (- (cos eps) (cos x)) (if (<= eps 2.3e-6) (- (* eps (sin x))) (+ (cos eps) -1.0))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.023) {
tmp = cos(eps) - cos(x);
} else if (eps <= 2.3e-6) {
tmp = -(eps * sin(x));
} else {
tmp = cos(eps) + -1.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.023d0)) then
tmp = cos(eps) - cos(x)
else if (eps <= 2.3d-6) then
tmp = -(eps * sin(x))
else
tmp = cos(eps) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -0.023) {
tmp = Math.cos(eps) - Math.cos(x);
} else if (eps <= 2.3e-6) {
tmp = -(eps * Math.sin(x));
} else {
tmp = Math.cos(eps) + -1.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.023: tmp = math.cos(eps) - math.cos(x) elif eps <= 2.3e-6: tmp = -(eps * math.sin(x)) else: tmp = math.cos(eps) + -1.0 return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.023) tmp = Float64(cos(eps) - cos(x)); elseif (eps <= 2.3e-6) tmp = Float64(-Float64(eps * sin(x))); else tmp = Float64(cos(eps) + -1.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -0.023) tmp = cos(eps) - cos(x); elseif (eps <= 2.3e-6) tmp = -(eps * sin(x)); else tmp = cos(eps) + -1.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.023], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.3e-6], (-N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.023:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{elif}\;\varepsilon \leq 2.3 \cdot 10^{-6}:\\
\;\;\;\;-\varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon + -1\\
\end{array}
\end{array}
if eps < -0.023Initial program 57.0%
Taylor expanded in x around 0 58.8%
if -0.023 < eps < 2.3e-6Initial program 26.1%
Taylor expanded in eps around 0 83.3%
mul-1-neg83.3%
*-commutative83.3%
distribute-rgt-neg-in83.3%
Simplified83.3%
if 2.3e-6 < eps Initial program 63.1%
Taylor expanded in x around 0 65.7%
Final simplification72.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)) (t_1 (* -0.5 (* eps eps))))
(if (<= eps -0.023)
t_0
(if (<= eps -2.1e-150)
t_1
(if (<= eps 1.45e-148) (* eps (- x)) (if (<= eps 0.00017) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double t_1 = -0.5 * (eps * eps);
double tmp;
if (eps <= -0.023) {
tmp = t_0;
} else if (eps <= -2.1e-150) {
tmp = t_1;
} else if (eps <= 1.45e-148) {
tmp = eps * -x;
} else if (eps <= 0.00017) {
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 = cos(eps) + (-1.0d0)
t_1 = (-0.5d0) * (eps * eps)
if (eps <= (-0.023d0)) then
tmp = t_0
else if (eps <= (-2.1d-150)) then
tmp = t_1
else if (eps <= 1.45d-148) then
tmp = eps * -x
else if (eps <= 0.00017d0) 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 = Math.cos(eps) + -1.0;
double t_1 = -0.5 * (eps * eps);
double tmp;
if (eps <= -0.023) {
tmp = t_0;
} else if (eps <= -2.1e-150) {
tmp = t_1;
} else if (eps <= 1.45e-148) {
tmp = eps * -x;
} else if (eps <= 0.00017) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 t_1 = -0.5 * (eps * eps) tmp = 0 if eps <= -0.023: tmp = t_0 elif eps <= -2.1e-150: tmp = t_1 elif eps <= 1.45e-148: tmp = eps * -x elif eps <= 0.00017: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) t_1 = Float64(-0.5 * Float64(eps * eps)) tmp = 0.0 if (eps <= -0.023) tmp = t_0; elseif (eps <= -2.1e-150) tmp = t_1; elseif (eps <= 1.45e-148) tmp = Float64(eps * Float64(-x)); elseif (eps <= 0.00017) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) + -1.0; t_1 = -0.5 * (eps * eps); tmp = 0.0; if (eps <= -0.023) tmp = t_0; elseif (eps <= -2.1e-150) tmp = t_1; elseif (eps <= 1.45e-148) tmp = eps * -x; elseif (eps <= 0.00017) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$1 = N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.023], t$95$0, If[LessEqual[eps, -2.1e-150], t$95$1, If[LessEqual[eps, 1.45e-148], N[(eps * (-x)), $MachinePrecision], If[LessEqual[eps, 0.00017], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
t_1 := -0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\mathbf{if}\;\varepsilon \leq -0.023:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -2.1 \cdot 10^{-150}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 1.45 \cdot 10^{-148}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00017:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -0.023 or 1.7e-4 < eps Initial program 60.1%
Taylor expanded in x around 0 61.8%
if -0.023 < eps < -2.1000000000000001e-150 or 1.4499999999999999e-148 < eps < 1.7e-4Initial program 4.2%
Taylor expanded in x around 0 4.6%
Taylor expanded in eps around 0 38.1%
unpow238.1%
Applied egg-rr38.1%
if -2.1000000000000001e-150 < eps < 1.4499999999999999e-148Initial program 43.5%
Taylor expanded in eps around 0 43.5%
mul-1-neg43.5%
unsub-neg43.5%
Simplified43.5%
Taylor expanded in x around 0 53.9%
associate-*r*53.9%
neg-mul-153.9%
Simplified53.9%
Final simplification54.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.023) (not (<= eps 2.4e-6))) (+ (cos eps) -1.0) (- (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.023) || !(eps <= 2.4e-6)) {
tmp = cos(eps) + -1.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 <= (-0.023d0)) .or. (.not. (eps <= 2.4d-6))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = -(eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.023) || !(eps <= 2.4e-6)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = -(eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.023) or not (eps <= 2.4e-6): tmp = math.cos(eps) + -1.0 else: tmp = -(eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.023) || !(eps <= 2.4e-6)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(-Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.023) || ~((eps <= 2.4e-6))) tmp = cos(eps) + -1.0; else tmp = -(eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.023], N[Not[LessEqual[eps, 2.4e-6]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], (-N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.023 \lor \neg \left(\varepsilon \leq 2.4 \cdot 10^{-6}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;-\varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -0.023 or 2.3999999999999999e-6 < eps Initial program 60.1%
Taylor expanded in x around 0 61.8%
if -0.023 < eps < 2.3999999999999999e-6Initial program 26.1%
Taylor expanded in eps around 0 83.3%
mul-1-neg83.3%
*-commutative83.3%
distribute-rgt-neg-in83.3%
Simplified83.3%
Final simplification72.2%
(FPCore (x eps) :precision binary64 (if (<= x 2.25e-75) (* -0.5 (* eps eps)) (* eps (- x))))
double code(double x, double eps) {
double tmp;
if (x <= 2.25e-75) {
tmp = -0.5 * (eps * eps);
} else {
tmp = eps * -x;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 2.25d-75) then
tmp = (-0.5d0) * (eps * eps)
else
tmp = eps * -x
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 2.25e-75) {
tmp = -0.5 * (eps * eps);
} else {
tmp = eps * -x;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 2.25e-75: tmp = -0.5 * (eps * eps) else: tmp = eps * -x return tmp
function code(x, eps) tmp = 0.0 if (x <= 2.25e-75) tmp = Float64(-0.5 * Float64(eps * eps)); else tmp = Float64(eps * Float64(-x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 2.25e-75) tmp = -0.5 * (eps * eps); else tmp = eps * -x; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 2.25e-75], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision], N[(eps * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.25 \cdot 10^{-75}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < 2.2500000000000002e-75Initial program 56.2%
Taylor expanded in x around 0 57.1%
Taylor expanded in eps around 0 28.9%
unpow228.9%
Applied egg-rr28.9%
if 2.2500000000000002e-75 < x Initial program 13.2%
Taylor expanded in eps around 0 5.7%
mul-1-neg5.7%
unsub-neg5.7%
Simplified5.7%
Taylor expanded in x around 0 12.4%
associate-*r*12.4%
neg-mul-112.4%
Simplified12.4%
Final simplification24.1%
(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 43.6%
Taylor expanded in eps around 0 15.0%
mul-1-neg15.0%
unsub-neg15.0%
Simplified15.0%
Taylor expanded in x around 0 18.9%
associate-*r*18.9%
neg-mul-118.9%
Simplified18.9%
Final simplification18.9%
herbie shell --seed 2024020
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))