
(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 15 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)))) (* (fma (sin x) (cos (* 0.5 eps)) (* (cos x) t_0)) (* t_0 -2.0))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return fma(sin(x), cos((0.5 * eps)), (cos(x) * t_0)) * (t_0 * -2.0);
}
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(fma(sin(x), cos(Float64(0.5 * eps)), Float64(cos(x) * t_0)) * Float64(t_0 * -2.0)) end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
\mathsf{fma}\left(\sin x, \cos \left(0.5 \cdot \varepsilon\right), \cos x \cdot t_0\right) \cdot \left(t_0 \cdot -2\right)
\end{array}
\end{array}
Initial program 36.7%
diff-cos45.8%
div-inv45.8%
metadata-eval45.8%
div-inv45.8%
+-commutative45.8%
metadata-eval45.8%
Applied egg-rr45.8%
*-commutative45.8%
+-commutative45.8%
associate--l+74.9%
+-inverses74.9%
distribute-lft-in74.9%
metadata-eval74.9%
*-commutative74.9%
associate-+r+74.9%
+-commutative74.9%
Simplified74.9%
Taylor expanded in x around -inf 74.9%
cancel-sign-sub-inv74.9%
metadata-eval74.9%
count-274.9%
distribute-lft-in74.9%
sin-sum99.4%
Applied egg-rr99.4%
fma-def99.4%
distribute-rgt-in99.4%
distribute-lft-out99.4%
metadata-eval99.4%
distribute-rgt-in99.4%
distribute-lft-out99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in eps around inf 99.4%
*-commutative99.4%
*-commutative99.4%
*-commutative99.4%
fma-def99.4%
associate-*l*99.4%
fma-def99.4%
+-commutative99.4%
*-commutative99.4%
*-commutative99.4%
fma-def99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (+ (* (cos x) t_0) (* (sin x) (cos (* 0.5 eps))))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * ((cos(x) * t_0) + (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 * ((cos(x) * t_0) + (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 * ((Math.cos(x) * t_0) + (Math.sin(x) * Math.cos((0.5 * eps)))));
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) return -2.0 * (t_0 * ((math.cos(x) * t_0) + (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(cos(x) * t_0) + 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 * ((cos(x) * t_0) + (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[(N[Cos[x], $MachinePrecision] * t$95$0), $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(\cos x \cdot t_0 + \sin x \cdot \cos \left(0.5 \cdot \varepsilon\right)\right)\right)
\end{array}
\end{array}
Initial program 36.7%
diff-cos45.8%
div-inv45.8%
metadata-eval45.8%
div-inv45.8%
+-commutative45.8%
metadata-eval45.8%
Applied egg-rr45.8%
*-commutative45.8%
+-commutative45.8%
associate--l+74.9%
+-inverses74.9%
distribute-lft-in74.9%
metadata-eval74.9%
*-commutative74.9%
associate-+r+74.9%
+-commutative74.9%
Simplified74.9%
Taylor expanded in x around -inf 74.9%
cancel-sign-sub-inv74.9%
metadata-eval74.9%
count-274.9%
distribute-lft-in74.9%
sin-sum99.4%
Applied egg-rr99.4%
fma-def99.4%
distribute-rgt-in99.4%
distribute-lft-out99.4%
metadata-eval99.4%
distribute-rgt-in99.4%
distribute-lft-out99.4%
metadata-eval99.4%
Simplified99.4%
fma-udef99.4%
*-rgt-identity99.4%
*-rgt-identity99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.000145) (not (<= eps 0.00013)))
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps))))
(+
(* (cos x) (* (* eps eps) -0.5))
(* (sin x) (- (* (pow eps 3.0) 0.16666666666666666) eps)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000145) || !(eps <= 0.00013)) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
} else {
tmp = (cos(x) * ((eps * eps) * -0.5)) + (sin(x) * ((pow(eps, 3.0) * 0.16666666666666666) - eps));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.000145d0)) .or. (.not. (eps <= 0.00013d0))) then
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)))
else
tmp = (cos(x) * ((eps * eps) * (-0.5d0))) + (sin(x) * (((eps ** 3.0d0) * 0.16666666666666666d0) - eps))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.000145) || !(eps <= 0.00013)) {
tmp = (Math.cos(x) * Math.cos(eps)) - (Math.cos(x) + (Math.sin(x) * Math.sin(eps)));
} else {
tmp = (Math.cos(x) * ((eps * eps) * -0.5)) + (Math.sin(x) * ((Math.pow(eps, 3.0) * 0.16666666666666666) - eps));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000145) or not (eps <= 0.00013): tmp = (math.cos(x) * math.cos(eps)) - (math.cos(x) + (math.sin(x) * math.sin(eps))) else: tmp = (math.cos(x) * ((eps * eps) * -0.5)) + (math.sin(x) * ((math.pow(eps, 3.0) * 0.16666666666666666) - eps)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000145) || !(eps <= 0.00013)) tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(x) * sin(eps)))); else tmp = Float64(Float64(cos(x) * Float64(Float64(eps * eps) * -0.5)) + Float64(sin(x) * Float64(Float64((eps ^ 3.0) * 0.16666666666666666) - eps))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000145) || ~((eps <= 0.00013))) tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps))); else tmp = (cos(x) * ((eps * eps) * -0.5)) + (sin(x) * (((eps ^ 3.0) * 0.16666666666666666) - eps)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000145], N[Not[LessEqual[eps, 0.00013]], $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[Cos[x], $MachinePrecision] * N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(N[Power[eps, 3.0], $MachinePrecision] * 0.16666666666666666), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000145 \lor \neg \left(\varepsilon \leq 0.00013\right):\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\right) + \sin x \cdot \left({\varepsilon}^{3} \cdot 0.16666666666666666 - \varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.45e-4 or 1.29999999999999989e-4 < eps Initial program 50.9%
sub-neg50.9%
cos-sum98.7%
associate-+l-98.7%
fma-neg98.7%
Applied egg-rr98.7%
Taylor expanded in x around inf 98.7%
if -1.45e-4 < eps < 1.29999999999999989e-4Initial program 21.9%
expm1-log1p-u21.9%
Applied egg-rr21.9%
Taylor expanded in eps around 0 99.9%
+-commutative99.9%
associate-+l+99.9%
associate-*r*99.9%
mul-1-neg99.9%
distribute-lft-neg-out99.9%
distribute-rgt-in99.9%
+-commutative99.9%
associate-*r*99.9%
*-commutative99.9%
*-commutative99.9%
unpow299.9%
+-commutative99.9%
sub-neg99.9%
Simplified99.9%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (cos x) (cos eps))) (t_1 (* (sin x) (sin eps))))
(if (<= eps -0.000145)
(- (- t_0 t_1) (cos x))
(if (<= eps 0.00017)
(+
(* (cos x) (* (* eps eps) -0.5))
(* (sin x) (- (* (pow eps 3.0) 0.16666666666666666) eps)))
(- t_0 (+ (cos x) t_1))))))
double code(double x, double eps) {
double t_0 = cos(x) * cos(eps);
double t_1 = sin(x) * sin(eps);
double tmp;
if (eps <= -0.000145) {
tmp = (t_0 - t_1) - cos(x);
} else if (eps <= 0.00017) {
tmp = (cos(x) * ((eps * eps) * -0.5)) + (sin(x) * ((pow(eps, 3.0) * 0.16666666666666666) - eps));
} else {
tmp = t_0 - (cos(x) + t_1);
}
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(x) * cos(eps)
t_1 = sin(x) * sin(eps)
if (eps <= (-0.000145d0)) then
tmp = (t_0 - t_1) - cos(x)
else if (eps <= 0.00017d0) then
tmp = (cos(x) * ((eps * eps) * (-0.5d0))) + (sin(x) * (((eps ** 3.0d0) * 0.16666666666666666d0) - eps))
else
tmp = t_0 - (cos(x) + t_1)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(x) * Math.cos(eps);
double t_1 = Math.sin(x) * Math.sin(eps);
double tmp;
if (eps <= -0.000145) {
tmp = (t_0 - t_1) - Math.cos(x);
} else if (eps <= 0.00017) {
tmp = (Math.cos(x) * ((eps * eps) * -0.5)) + (Math.sin(x) * ((Math.pow(eps, 3.0) * 0.16666666666666666) - eps));
} else {
tmp = t_0 - (Math.cos(x) + t_1);
}
return tmp;
}
def code(x, eps): t_0 = math.cos(x) * math.cos(eps) t_1 = math.sin(x) * math.sin(eps) tmp = 0 if eps <= -0.000145: tmp = (t_0 - t_1) - math.cos(x) elif eps <= 0.00017: tmp = (math.cos(x) * ((eps * eps) * -0.5)) + (math.sin(x) * ((math.pow(eps, 3.0) * 0.16666666666666666) - eps)) else: tmp = t_0 - (math.cos(x) + t_1) return tmp
function code(x, eps) t_0 = Float64(cos(x) * cos(eps)) t_1 = Float64(sin(x) * sin(eps)) tmp = 0.0 if (eps <= -0.000145) tmp = Float64(Float64(t_0 - t_1) - cos(x)); elseif (eps <= 0.00017) tmp = Float64(Float64(cos(x) * Float64(Float64(eps * eps) * -0.5)) + Float64(sin(x) * Float64(Float64((eps ^ 3.0) * 0.16666666666666666) - eps))); else tmp = Float64(t_0 - Float64(cos(x) + t_1)); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(x) * cos(eps); t_1 = sin(x) * sin(eps); tmp = 0.0; if (eps <= -0.000145) tmp = (t_0 - t_1) - cos(x); elseif (eps <= 0.00017) tmp = (cos(x) * ((eps * eps) * -0.5)) + (sin(x) * (((eps ^ 3.0) * 0.16666666666666666) - eps)); else tmp = t_0 - (cos(x) + t_1); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.000145], N[(N[(t$95$0 - t$95$1), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00017], N[(N[(N[Cos[x], $MachinePrecision] * N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(N[Power[eps, 3.0], $MachinePrecision] * 0.16666666666666666), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - N[(N[Cos[x], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \cos \varepsilon\\
t_1 := \sin x \cdot \sin \varepsilon\\
\mathbf{if}\;\varepsilon \leq -0.000145:\\
\;\;\;\;\left(t_0 - t_1\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 0.00017:\\
\;\;\;\;\cos x \cdot \left(\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\right) + \sin x \cdot \left({\varepsilon}^{3} \cdot 0.16666666666666666 - \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 - \left(\cos x + t_1\right)\\
\end{array}
\end{array}
if eps < -1.45e-4Initial program 51.9%
cos-sum98.7%
Applied egg-rr98.7%
if -1.45e-4 < eps < 1.7e-4Initial program 21.9%
expm1-log1p-u21.9%
Applied egg-rr21.9%
Taylor expanded in eps around 0 99.9%
+-commutative99.9%
associate-+l+99.9%
associate-*r*99.9%
mul-1-neg99.9%
distribute-lft-neg-out99.9%
distribute-rgt-in99.9%
+-commutative99.9%
associate-*r*99.9%
*-commutative99.9%
*-commutative99.9%
unpow299.9%
+-commutative99.9%
sub-neg99.9%
Simplified99.9%
if 1.7e-4 < eps Initial program 50.0%
sub-neg50.0%
cos-sum98.8%
associate-+l-98.8%
fma-neg98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 98.8%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (+ (sin x) (* t_0 (cos (* 0.5 (+ x x)))))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * (sin(x) + (t_0 * cos((0.5 * (x + x))))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = sin((0.5d0 * eps))
code = (-2.0d0) * (t_0 * (sin(x) + (t_0 * cos((0.5d0 * (x + x))))))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
return -2.0 * (t_0 * (Math.sin(x) + (t_0 * Math.cos((0.5 * (x + x))))));
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) return -2.0 * (t_0 * (math.sin(x) + (t_0 * math.cos((0.5 * (x + x))))))
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * Float64(sin(x) + Float64(t_0 * cos(Float64(0.5 * Float64(x + x))))))) end
function tmp = code(x, eps) t_0 = sin((0.5 * eps)); tmp = -2.0 * (t_0 * (sin(x) + (t_0 * cos((0.5 * (x + 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[(t$95$0 * N[Cos[N[(0.5 * N[(x + x), $MachinePrecision]), $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(\sin x + t_0 \cdot \cos \left(0.5 \cdot \left(x + x\right)\right)\right)\right)
\end{array}
\end{array}
Initial program 36.7%
diff-cos45.8%
div-inv45.8%
metadata-eval45.8%
div-inv45.8%
+-commutative45.8%
metadata-eval45.8%
Applied egg-rr45.8%
*-commutative45.8%
+-commutative45.8%
associate--l+74.9%
+-inverses74.9%
distribute-lft-in74.9%
metadata-eval74.9%
*-commutative74.9%
associate-+r+74.9%
+-commutative74.9%
Simplified74.9%
Taylor expanded in x around -inf 74.9%
cancel-sign-sub-inv74.9%
metadata-eval74.9%
count-274.9%
distribute-rgt-in74.9%
*-commutative74.9%
sin-sum99.4%
Applied egg-rr99.4%
Taylor expanded in eps around 0 76.5%
Final simplification76.5%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.00056)
(* -2.0 (pow (sin (* 0.5 eps)) 2.0))
(if (<= eps 0.185)
(- (* -0.5 (* eps (* eps (cos x)))) (* (sin x) eps))
(- (cos eps) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.00056) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
} else if (eps <= 0.185) {
tmp = (-0.5 * (eps * (eps * cos(x)))) - (sin(x) * eps);
} else {
tmp = cos(eps) - cos(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-0.00056d0)) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
else if (eps <= 0.185d0) then
tmp = ((-0.5d0) * (eps * (eps * cos(x)))) - (sin(x) * eps)
else
tmp = cos(eps) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -0.00056) {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
} else if (eps <= 0.185) {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) - (Math.sin(x) * eps);
} else {
tmp = Math.cos(eps) - Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.00056: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) elif eps <= 0.185: tmp = (-0.5 * (eps * (eps * math.cos(x)))) - (math.sin(x) * eps) else: tmp = math.cos(eps) - math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.00056) tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); elseif (eps <= 0.185) tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) - Float64(sin(x) * eps)); else tmp = Float64(cos(eps) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -0.00056) tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); elseif (eps <= 0.185) tmp = (-0.5 * (eps * (eps * cos(x)))) - (sin(x) * eps); else tmp = cos(eps) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.00056], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.185], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00056:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{elif}\;\varepsilon \leq 0.185:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) - \sin x \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\end{array}
\end{array}
if eps < -5.5999999999999995e-4Initial program 51.9%
diff-cos52.7%
div-inv52.7%
metadata-eval52.7%
div-inv52.7%
+-commutative52.7%
metadata-eval52.7%
Applied egg-rr52.7%
*-commutative52.7%
+-commutative52.7%
associate--l+53.7%
+-inverses53.7%
distribute-lft-in53.7%
metadata-eval53.7%
*-commutative53.7%
associate-+r+53.6%
+-commutative53.6%
Simplified53.6%
Taylor expanded in x around 0 54.2%
if -5.5999999999999995e-4 < eps < 0.185Initial program 21.8%
Taylor expanded in eps around 0 99.2%
+-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
unpow299.2%
associate-*l*99.2%
Simplified99.2%
if 0.185 < eps Initial program 50.7%
Taylor expanded in x around 0 53.3%
Final simplification76.1%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 eps)) (sin (* 0.5 (- eps (* x -2.0)))))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * eps)) * 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((0.5d0 * eps)) * sin((0.5d0 * (eps - (x * (-2.0d0))))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * eps)) * Math.sin((0.5 * (eps - (x * -2.0)))));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * eps)) * math.sin((0.5 * (eps - (x * -2.0)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * eps)) * sin((0.5 * (eps - (x * -2.0))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * eps), $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(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right)\right)
\end{array}
Initial program 36.7%
diff-cos45.8%
div-inv45.8%
metadata-eval45.8%
div-inv45.8%
+-commutative45.8%
metadata-eval45.8%
Applied egg-rr45.8%
*-commutative45.8%
+-commutative45.8%
associate--l+74.9%
+-inverses74.9%
distribute-lft-in74.9%
metadata-eval74.9%
*-commutative74.9%
associate-+r+74.9%
+-commutative74.9%
Simplified74.9%
Taylor expanded in x around -inf 74.9%
Final simplification74.9%
(FPCore (x eps)
:precision binary64
(if (<= eps -1.4e-6)
(+ (cos eps) -1.0)
(if (<= eps 1.8e-112)
(* (sin x) (- eps))
(if (<= eps 235000000000.0)
(/ (- (pow (sin eps) 2.0)) 2.0)
(- (cos eps) (cos x))))))
double code(double x, double eps) {
double tmp;
if (eps <= -1.4e-6) {
tmp = cos(eps) + -1.0;
} else if (eps <= 1.8e-112) {
tmp = sin(x) * -eps;
} else if (eps <= 235000000000.0) {
tmp = -pow(sin(eps), 2.0) / 2.0;
} else {
tmp = cos(eps) - cos(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-1.4d-6)) then
tmp = cos(eps) + (-1.0d0)
else if (eps <= 1.8d-112) then
tmp = sin(x) * -eps
else if (eps <= 235000000000.0d0) then
tmp = -(sin(eps) ** 2.0d0) / 2.0d0
else
tmp = cos(eps) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -1.4e-6) {
tmp = Math.cos(eps) + -1.0;
} else if (eps <= 1.8e-112) {
tmp = Math.sin(x) * -eps;
} else if (eps <= 235000000000.0) {
tmp = -Math.pow(Math.sin(eps), 2.0) / 2.0;
} else {
tmp = Math.cos(eps) - Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -1.4e-6: tmp = math.cos(eps) + -1.0 elif eps <= 1.8e-112: tmp = math.sin(x) * -eps elif eps <= 235000000000.0: tmp = -math.pow(math.sin(eps), 2.0) / 2.0 else: tmp = math.cos(eps) - math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -1.4e-6) tmp = Float64(cos(eps) + -1.0); elseif (eps <= 1.8e-112) tmp = Float64(sin(x) * Float64(-eps)); elseif (eps <= 235000000000.0) tmp = Float64(Float64(-(sin(eps) ^ 2.0)) / 2.0); else tmp = Float64(cos(eps) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -1.4e-6) tmp = cos(eps) + -1.0; elseif (eps <= 1.8e-112) tmp = sin(x) * -eps; elseif (eps <= 235000000000.0) tmp = -(sin(eps) ^ 2.0) / 2.0; else tmp = cos(eps) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -1.4e-6], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[eps, 1.8e-112], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], If[LessEqual[eps, 235000000000.0], N[((-N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision]) / 2.0), $MachinePrecision], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.4 \cdot 10^{-6}:\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{elif}\;\varepsilon \leq 1.8 \cdot 10^{-112}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 235000000000:\\
\;\;\;\;\frac{-{\sin \varepsilon}^{2}}{2}\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\end{array}
\end{array}
if eps < -1.39999999999999994e-6Initial program 51.9%
Taylor expanded in x around 0 53.8%
if -1.39999999999999994e-6 < eps < 1.8e-112Initial program 25.3%
Taylor expanded in eps around 0 88.4%
mul-1-neg88.4%
*-commutative88.4%
distribute-rgt-neg-in88.4%
Simplified88.4%
if 1.8e-112 < eps < 2.35e11Initial program 4.1%
Taylor expanded in x around 0 5.4%
flip--5.4%
metadata-eval5.4%
Applied egg-rr5.4%
Taylor expanded in eps around inf 5.4%
unpow25.4%
sub-1-cos59.1%
unpow259.1%
Simplified59.1%
Taylor expanded in eps around 0 59.1%
if 2.35e11 < eps Initial program 51.4%
Taylor expanded in x around 0 54.1%
Final simplification68.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* 0.5 eps))))
(if (or (<= x -8e-87) (not (<= x 4.7e-7)))
(* -2.0 (* (sin x) t_0))
(* -2.0 (pow t_0 2.0)))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
double tmp;
if ((x <= -8e-87) || !(x <= 4.7e-7)) {
tmp = -2.0 * (sin(x) * t_0);
} else {
tmp = -2.0 * pow(t_0, 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((0.5d0 * eps))
if ((x <= (-8d-87)) .or. (.not. (x <= 4.7d-7))) then
tmp = (-2.0d0) * (sin(x) * t_0)
else
tmp = (-2.0d0) * (t_0 ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
double tmp;
if ((x <= -8e-87) || !(x <= 4.7e-7)) {
tmp = -2.0 * (Math.sin(x) * t_0);
} else {
tmp = -2.0 * Math.pow(t_0, 2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) tmp = 0 if (x <= -8e-87) or not (x <= 4.7e-7): tmp = -2.0 * (math.sin(x) * t_0) else: tmp = -2.0 * math.pow(t_0, 2.0) return tmp
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) tmp = 0.0 if ((x <= -8e-87) || !(x <= 4.7e-7)) tmp = Float64(-2.0 * Float64(sin(x) * t_0)); else tmp = Float64(-2.0 * (t_0 ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((0.5 * eps)); tmp = 0.0; if ((x <= -8e-87) || ~((x <= 4.7e-7))) tmp = -2.0 * (sin(x) * t_0); else tmp = -2.0 * (t_0 ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -8e-87], N[Not[LessEqual[x, 4.7e-7]], $MachinePrecision]], N[(-2.0 * N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
\mathbf{if}\;x \leq -8 \cdot 10^{-87} \lor \neg \left(x \leq 4.7 \cdot 10^{-7}\right):\\
\;\;\;\;-2 \cdot \left(\sin x \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -8.00000000000000014e-87 or 4.7e-7 < x Initial program 9.6%
diff-cos10.3%
div-inv10.3%
metadata-eval10.3%
div-inv10.3%
+-commutative10.3%
metadata-eval10.3%
Applied egg-rr10.3%
*-commutative10.3%
+-commutative10.3%
associate--l+56.4%
+-inverses56.4%
distribute-lft-in56.4%
metadata-eval56.4%
*-commutative56.4%
associate-+r+56.5%
+-commutative56.5%
Simplified56.5%
Taylor expanded in x around -inf 56.5%
Taylor expanded in eps around 0 52.2%
if -8.00000000000000014e-87 < x < 4.7e-7Initial program 72.2%
diff-cos92.1%
div-inv92.1%
metadata-eval92.1%
div-inv92.1%
+-commutative92.1%
metadata-eval92.1%
Applied egg-rr92.1%
*-commutative92.1%
+-commutative92.1%
associate--l+99.0%
+-inverses99.0%
distribute-lft-in99.0%
metadata-eval99.0%
*-commutative99.0%
associate-+r+99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in x around 0 92.1%
Final simplification69.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.36e-13) (not (<= eps 1.8e-112))) (* -2.0 (pow (sin (* 0.5 eps)) 2.0)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.36e-13) || !(eps <= 1.8e-112)) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
} else {
tmp = sin(x) * -eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.36d-13)) .or. (.not. (eps <= 1.8d-112))) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.36e-13) || !(eps <= 1.8e-112)) {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.36e-13) or not (eps <= 1.8e-112): tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.36e-13) || !(eps <= 1.8e-112)) tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.36e-13) || ~((eps <= 1.8e-112))) tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.36e-13], N[Not[LessEqual[eps, 1.8e-112]], $MachinePrecision]], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.36 \cdot 10^{-13} \lor \neg \left(\varepsilon \leq 1.8 \cdot 10^{-112}\right):\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.36000000000000001e-13 or 1.8e-112 < eps Initial program 43.9%
diff-cos52.8%
div-inv52.8%
metadata-eval52.8%
div-inv52.8%
+-commutative52.8%
metadata-eval52.8%
Applied egg-rr52.8%
*-commutative52.8%
+-commutative52.8%
associate--l+58.5%
+-inverses58.5%
distribute-lft-in58.5%
metadata-eval58.5%
*-commutative58.5%
associate-+r+58.5%
+-commutative58.5%
Simplified58.5%
Taylor expanded in x around 0 53.7%
if -1.36000000000000001e-13 < eps < 1.8e-112Initial program 25.9%
Taylor expanded in eps around 0 90.4%
mul-1-neg90.4%
*-commutative90.4%
distribute-rgt-neg-in90.4%
Simplified90.4%
Final simplification68.3%
(FPCore (x eps)
:precision binary64
(if (<= eps -1.3e-5)
(+ (cos eps) -1.0)
(if (<= eps 1.7e-112)
(* (sin x) (- eps))
(if (<= eps 235000000000.0) (* (* eps eps) -0.5) (- (cos eps) (cos x))))))
double code(double x, double eps) {
double tmp;
if (eps <= -1.3e-5) {
tmp = cos(eps) + -1.0;
} else if (eps <= 1.7e-112) {
tmp = sin(x) * -eps;
} else if (eps <= 235000000000.0) {
tmp = (eps * eps) * -0.5;
} else {
tmp = cos(eps) - cos(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-1.3d-5)) then
tmp = cos(eps) + (-1.0d0)
else if (eps <= 1.7d-112) then
tmp = sin(x) * -eps
else if (eps <= 235000000000.0d0) then
tmp = (eps * eps) * (-0.5d0)
else
tmp = cos(eps) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -1.3e-5) {
tmp = Math.cos(eps) + -1.0;
} else if (eps <= 1.7e-112) {
tmp = Math.sin(x) * -eps;
} else if (eps <= 235000000000.0) {
tmp = (eps * eps) * -0.5;
} else {
tmp = Math.cos(eps) - Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -1.3e-5: tmp = math.cos(eps) + -1.0 elif eps <= 1.7e-112: tmp = math.sin(x) * -eps elif eps <= 235000000000.0: tmp = (eps * eps) * -0.5 else: tmp = math.cos(eps) - math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -1.3e-5) tmp = Float64(cos(eps) + -1.0); elseif (eps <= 1.7e-112) tmp = Float64(sin(x) * Float64(-eps)); elseif (eps <= 235000000000.0) tmp = Float64(Float64(eps * eps) * -0.5); else tmp = Float64(cos(eps) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -1.3e-5) tmp = cos(eps) + -1.0; elseif (eps <= 1.7e-112) tmp = sin(x) * -eps; elseif (eps <= 235000000000.0) tmp = (eps * eps) * -0.5; else tmp = cos(eps) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -1.3e-5], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[eps, 1.7e-112], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], If[LessEqual[eps, 235000000000.0], N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.3 \cdot 10^{-5}:\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{elif}\;\varepsilon \leq 1.7 \cdot 10^{-112}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 235000000000:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\end{array}
\end{array}
if eps < -1.29999999999999992e-5Initial program 51.9%
Taylor expanded in x around 0 53.8%
if -1.29999999999999992e-5 < eps < 1.6999999999999999e-112Initial program 25.3%
Taylor expanded in eps around 0 88.4%
mul-1-neg88.4%
*-commutative88.4%
distribute-rgt-neg-in88.4%
Simplified88.4%
if 1.6999999999999999e-112 < eps < 2.35e11Initial program 4.1%
Taylor expanded in x around 0 5.4%
Taylor expanded in eps around 0 58.7%
*-commutative58.7%
unpow258.7%
Simplified58.7%
if 2.35e11 < eps Initial program 51.4%
Taylor expanded in x around 0 54.1%
Final simplification68.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)))
(if (<= eps -1.35e-5)
t_0
(if (<= eps 1.6e-112)
(* (sin x) (- eps))
(if (<= eps 0.18) (* (* eps eps) -0.5) t_0)))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double tmp;
if (eps <= -1.35e-5) {
tmp = t_0;
} else if (eps <= 1.6e-112) {
tmp = sin(x) * -eps;
} else if (eps <= 0.18) {
tmp = (eps * eps) * -0.5;
} 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 = cos(eps) + (-1.0d0)
if (eps <= (-1.35d-5)) then
tmp = t_0
else if (eps <= 1.6d-112) then
tmp = sin(x) * -eps
else if (eps <= 0.18d0) then
tmp = (eps * eps) * (-0.5d0)
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 tmp;
if (eps <= -1.35e-5) {
tmp = t_0;
} else if (eps <= 1.6e-112) {
tmp = Math.sin(x) * -eps;
} else if (eps <= 0.18) {
tmp = (eps * eps) * -0.5;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 tmp = 0 if eps <= -1.35e-5: tmp = t_0 elif eps <= 1.6e-112: tmp = math.sin(x) * -eps elif eps <= 0.18: tmp = (eps * eps) * -0.5 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) tmp = 0.0 if (eps <= -1.35e-5) tmp = t_0; elseif (eps <= 1.6e-112) tmp = Float64(sin(x) * Float64(-eps)); elseif (eps <= 0.18) tmp = Float64(Float64(eps * eps) * -0.5); else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) + -1.0; tmp = 0.0; if (eps <= -1.35e-5) tmp = t_0; elseif (eps <= 1.6e-112) tmp = sin(x) * -eps; elseif (eps <= 0.18) tmp = (eps * eps) * -0.5; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[eps, -1.35e-5], t$95$0, If[LessEqual[eps, 1.6e-112], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], If[LessEqual[eps, 0.18], N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
\mathbf{if}\;\varepsilon \leq -1.35 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 1.6 \cdot 10^{-112}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 0.18:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.3499999999999999e-5 or 0.17999999999999999 < eps Initial program 51.2%
Taylor expanded in x around 0 52.1%
if -1.3499999999999999e-5 < eps < 1.59999999999999997e-112Initial program 25.3%
Taylor expanded in eps around 0 88.4%
mul-1-neg88.4%
*-commutative88.4%
distribute-rgt-neg-in88.4%
Simplified88.4%
if 1.59999999999999997e-112 < eps < 0.17999999999999999Initial program 4.1%
Taylor expanded in x around 0 4.7%
Taylor expanded in eps around 0 61.0%
*-commutative61.0%
unpow261.0%
Simplified61.0%
Final simplification67.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -9.2e-7) (not (<= eps 0.18))) (+ (cos eps) -1.0) (* (* eps eps) -0.5)))
double code(double x, double eps) {
double tmp;
if ((eps <= -9.2e-7) || !(eps <= 0.18)) {
tmp = cos(eps) + -1.0;
} else {
tmp = (eps * eps) * -0.5;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-9.2d-7)) .or. (.not. (eps <= 0.18d0))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = (eps * eps) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -9.2e-7) || !(eps <= 0.18)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = (eps * eps) * -0.5;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -9.2e-7) or not (eps <= 0.18): tmp = math.cos(eps) + -1.0 else: tmp = (eps * eps) * -0.5 return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -9.2e-7) || !(eps <= 0.18)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(Float64(eps * eps) * -0.5); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -9.2e-7) || ~((eps <= 0.18))) tmp = cos(eps) + -1.0; else tmp = (eps * eps) * -0.5; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -9.2e-7], N[Not[LessEqual[eps, 0.18]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -9.2 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 0.18\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\end{array}
\end{array}
if eps < -9.1999999999999998e-7 or 0.17999999999999999 < eps Initial program 50.9%
Taylor expanded in x around 0 51.7%
if -9.1999999999999998e-7 < eps < 0.17999999999999999Initial program 21.9%
Taylor expanded in x around 0 22.0%
Taylor expanded in eps around 0 40.7%
*-commutative40.7%
unpow240.7%
Simplified40.7%
Final simplification46.3%
(FPCore (x eps) :precision binary64 (* (* eps eps) -0.5))
double code(double x, double eps) {
return (eps * eps) * -0.5;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (eps * eps) * (-0.5d0)
end function
public static double code(double x, double eps) {
return (eps * eps) * -0.5;
}
def code(x, eps): return (eps * eps) * -0.5
function code(x, eps) return Float64(Float64(eps * eps) * -0.5) end
function tmp = code(x, eps) tmp = (eps * eps) * -0.5; end
code[x_, eps_] := N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5
\end{array}
Initial program 36.7%
Taylor expanded in x around 0 37.2%
Taylor expanded in eps around 0 21.6%
*-commutative21.6%
unpow221.6%
Simplified21.6%
Final simplification21.6%
(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 36.7%
Taylor expanded in x around 0 37.2%
Taylor expanded in eps around 0 12.3%
Final simplification12.3%
herbie shell --seed 2023271
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))