
(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 11 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 (* eps 0.5))) (t_1 (- (sin x))))
(if (<= x -2.6e-8)
(fma t_1 (sin eps) (* (cos x) (+ (cos eps) -1.0)))
(if (<= x 2.2e-82)
(* -2.0 (* t_0 (+ t_0 (* x (cos (* eps 0.5))))))
(fma t_1 (sin eps) (- (* (cos x) (cos eps)) (cos x)))))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double t_1 = -sin(x);
double tmp;
if (x <= -2.6e-8) {
tmp = fma(t_1, sin(eps), (cos(x) * (cos(eps) + -1.0)));
} else if (x <= 2.2e-82) {
tmp = -2.0 * (t_0 * (t_0 + (x * cos((eps * 0.5)))));
} else {
tmp = fma(t_1, sin(eps), ((cos(x) * cos(eps)) - cos(x)));
}
return tmp;
}
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) t_1 = Float64(-sin(x)) tmp = 0.0 if (x <= -2.6e-8) tmp = fma(t_1, sin(eps), Float64(cos(x) * Float64(cos(eps) + -1.0))); elseif (x <= 2.2e-82) tmp = Float64(-2.0 * Float64(t_0 * Float64(t_0 + Float64(x * cos(Float64(eps * 0.5)))))); else tmp = fma(t_1, sin(eps), Float64(Float64(cos(x) * cos(eps)) - cos(x))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = (-N[Sin[x], $MachinePrecision])}, If[LessEqual[x, -2.6e-8], N[(t$95$1 * N[Sin[eps], $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.2e-82], N[(-2.0 * N[(t$95$0 * N[(t$95$0 + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[Sin[eps], $MachinePrecision] + N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
t_1 := -\sin x\\
\mathbf{if}\;x \leq -2.6 \cdot 10^{-8}:\\
\;\;\;\;\mathsf{fma}\left(t_1, \sin \varepsilon, \cos x \cdot \left(\cos \varepsilon + -1\right)\right)\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-82}:\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_1, \sin \varepsilon, \cos x \cdot \cos \varepsilon - \cos x\right)\\
\end{array}
\end{array}
if x < -2.6000000000000001e-8Initial program 7.2%
cos-sum55.4%
cancel-sign-sub-inv55.4%
fma-def55.5%
Applied egg-rr55.5%
Taylor expanded in x around inf 55.4%
*-commutative55.4%
neg-mul-155.4%
associate--l+99.1%
distribute-lft-neg-in99.1%
*-commutative99.1%
fma-def99.2%
*-commutative99.2%
Simplified99.2%
Taylor expanded in x around inf 99.2%
sub-neg99.2%
neg-mul-199.2%
distribute-rgt-out99.3%
Simplified99.3%
if -2.6000000000000001e-8 < x < 2.19999999999999986e-82Initial program 72.4%
diff-cos89.7%
div-inv89.7%
metadata-eval89.7%
div-inv89.7%
+-commutative89.7%
metadata-eval89.7%
Applied egg-rr89.7%
*-commutative89.7%
+-commutative89.7%
associate--l+99.5%
+-inverses99.5%
distribute-lft-in99.5%
metadata-eval99.5%
*-commutative99.5%
+-commutative99.5%
Simplified99.5%
add-log-exp71.6%
*-commutative71.6%
+-commutative71.6%
+-rgt-identity71.6%
Applied egg-rr71.6%
Taylor expanded in x around 0 99.5%
+-commutative99.5%
unpow299.5%
distribute-lft-out99.5%
*-commutative99.5%
*-commutative99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
if 2.19999999999999986e-82 < x Initial program 16.7%
cos-sum58.7%
cancel-sign-sub-inv58.7%
fma-def58.8%
Applied egg-rr58.8%
Taylor expanded in x around inf 58.7%
*-commutative58.7%
neg-mul-158.7%
associate--l+98.3%
distribute-lft-neg-in98.3%
*-commutative98.3%
fma-def98.4%
*-commutative98.4%
Simplified98.4%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -2.7e-8) (not (<= x 2.3e-82)))
(fma (- (sin x)) (sin eps) (* (cos x) (+ (cos eps) -1.0)))
(* -2.0 (* t_0 (+ t_0 (* x (cos (* eps 0.5)))))))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -2.7e-8) || !(x <= 2.3e-82)) {
tmp = fma(-sin(x), sin(eps), (cos(x) * (cos(eps) + -1.0)));
} else {
tmp = -2.0 * (t_0 * (t_0 + (x * cos((eps * 0.5)))));
}
return tmp;
}
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -2.7e-8) || !(x <= 2.3e-82)) tmp = fma(Float64(-sin(x)), sin(eps), Float64(cos(x) * Float64(cos(eps) + -1.0))); else tmp = Float64(-2.0 * Float64(t_0 * Float64(t_0 + Float64(x * cos(Float64(eps * 0.5)))))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -2.7e-8], N[Not[LessEqual[x, 2.3e-82]], $MachinePrecision]], N[((-N[Sin[x], $MachinePrecision]) * N[Sin[eps], $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(t$95$0 * N[(t$95$0 + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -2.7 \cdot 10^{-8} \lor \neg \left(x \leq 2.3 \cdot 10^{-82}\right):\\
\;\;\;\;\mathsf{fma}\left(-\sin x, \sin \varepsilon, \cos x \cdot \left(\cos \varepsilon + -1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if x < -2.70000000000000002e-8 or 2.29999999999999997e-82 < x Initial program 12.0%
cos-sum57.1%
cancel-sign-sub-inv57.1%
fma-def57.1%
Applied egg-rr57.1%
Taylor expanded in x around inf 57.1%
*-commutative57.1%
neg-mul-157.1%
associate--l+98.7%
distribute-lft-neg-in98.7%
*-commutative98.7%
fma-def98.8%
*-commutative98.8%
Simplified98.8%
Taylor expanded in x around inf 98.8%
sub-neg98.8%
neg-mul-198.8%
distribute-rgt-out98.8%
Simplified98.8%
if -2.70000000000000002e-8 < x < 2.29999999999999997e-82Initial program 72.4%
diff-cos89.7%
div-inv89.7%
metadata-eval89.7%
div-inv89.7%
+-commutative89.7%
metadata-eval89.7%
Applied egg-rr89.7%
*-commutative89.7%
+-commutative89.7%
associate--l+99.5%
+-inverses99.5%
distribute-lft-in99.5%
metadata-eval99.5%
*-commutative99.5%
+-commutative99.5%
Simplified99.5%
add-log-exp71.6%
*-commutative71.6%
+-commutative71.6%
+-rgt-identity71.6%
Applied egg-rr71.6%
Taylor expanded in x around 0 99.5%
+-commutative99.5%
unpow299.5%
distribute-lft-out99.5%
*-commutative99.5%
*-commutative99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -2.85e-8) (not (<= x 1.8e-82)))
(- (* (cos x) (+ (cos eps) -1.0)) (* (sin x) (sin eps)))
(* -2.0 (* t_0 (+ t_0 (* x (cos (* eps 0.5)))))))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((x <= -2.85e-8) || !(x <= 1.8e-82)) {
tmp = (cos(x) * (cos(eps) + -1.0)) - (sin(x) * sin(eps));
} else {
tmp = -2.0 * (t_0 * (t_0 + (x * cos((eps * 0.5)))));
}
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 <= (-2.85d-8)) .or. (.not. (x <= 1.8d-82))) then
tmp = (cos(x) * (cos(eps) + (-1.0d0))) - (sin(x) * sin(eps))
else
tmp = (-2.0d0) * (t_0 * (t_0 + (x * cos((eps * 0.5d0)))))
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 <= -2.85e-8) || !(x <= 1.8e-82)) {
tmp = (Math.cos(x) * (Math.cos(eps) + -1.0)) - (Math.sin(x) * Math.sin(eps));
} else {
tmp = -2.0 * (t_0 * (t_0 + (x * Math.cos((eps * 0.5)))));
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (x <= -2.85e-8) or not (x <= 1.8e-82): tmp = (math.cos(x) * (math.cos(eps) + -1.0)) - (math.sin(x) * math.sin(eps)) else: tmp = -2.0 * (t_0 * (t_0 + (x * math.cos((eps * 0.5))))) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if ((x <= -2.85e-8) || !(x <= 1.8e-82)) tmp = Float64(Float64(cos(x) * Float64(cos(eps) + -1.0)) - Float64(sin(x) * sin(eps))); else tmp = Float64(-2.0 * Float64(t_0 * Float64(t_0 + Float64(x * cos(Float64(eps * 0.5)))))); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((x <= -2.85e-8) || ~((x <= 1.8e-82))) tmp = (cos(x) * (cos(eps) + -1.0)) - (sin(x) * sin(eps)); else tmp = -2.0 * (t_0 * (t_0 + (x * cos((eps * 0.5))))); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -2.85e-8], N[Not[LessEqual[x, 1.8e-82]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(t$95$0 * N[(t$95$0 + N[(x * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -2.85 \cdot 10^{-8} \lor \neg \left(x \leq 1.8 \cdot 10^{-82}\right):\\
\;\;\;\;\cos x \cdot \left(\cos \varepsilon + -1\right) - \sin x \cdot \sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(t_0 + x \cdot \cos \left(\varepsilon \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if x < -2.85000000000000004e-8 or 1.79999999999999999e-82 < x Initial program 12.0%
cos-sum57.1%
cancel-sign-sub-inv57.1%
fma-def57.1%
Applied egg-rr57.1%
Taylor expanded in x around inf 57.1%
*-commutative57.1%
neg-mul-157.1%
associate--l+98.7%
distribute-lft-neg-in98.7%
*-commutative98.7%
fma-def98.8%
*-commutative98.8%
Simplified98.8%
Taylor expanded in x around inf 57.1%
+-commutative57.1%
*-commutative57.1%
+-commutative57.1%
associate-+r-98.7%
+-commutative98.7%
mul-1-neg98.7%
unsub-neg98.7%
*-rgt-identity98.7%
distribute-lft-out--98.7%
sub-neg98.7%
metadata-eval98.7%
*-commutative98.7%
Simplified98.7%
if -2.85000000000000004e-8 < x < 1.79999999999999999e-82Initial program 72.4%
diff-cos89.7%
div-inv89.7%
metadata-eval89.7%
div-inv89.7%
+-commutative89.7%
metadata-eval89.7%
Applied egg-rr89.7%
*-commutative89.7%
+-commutative89.7%
associate--l+99.5%
+-inverses99.5%
distribute-lft-in99.5%
metadata-eval99.5%
*-commutative99.5%
+-commutative99.5%
Simplified99.5%
add-log-exp71.6%
*-commutative71.6%
+-commutative71.6%
+-rgt-identity71.6%
Applied egg-rr71.6%
Taylor expanded in x around 0 99.5%
+-commutative99.5%
unpow299.5%
distribute-lft-out99.5%
*-commutative99.5%
*-commutative99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.006)
(- (cos eps) (cos x))
(if (<= eps 0.00165)
(- (* -0.5 (* eps (* eps (cos x)))) (* (sin x) eps))
(* -2.0 (pow (sin (* eps 0.5)) 2.0)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.006) {
tmp = cos(eps) - cos(x);
} else if (eps <= 0.00165) {
tmp = (-0.5 * (eps * (eps * cos(x)))) - (sin(x) * eps);
} 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.006d0)) then
tmp = cos(eps) - cos(x)
else if (eps <= 0.00165d0) then
tmp = ((-0.5d0) * (eps * (eps * cos(x)))) - (sin(x) * eps)
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.006) {
tmp = Math.cos(eps) - Math.cos(x);
} else if (eps <= 0.00165) {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) - (Math.sin(x) * eps);
} else {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.006: tmp = math.cos(eps) - math.cos(x) elif eps <= 0.00165: tmp = (-0.5 * (eps * (eps * math.cos(x)))) - (math.sin(x) * eps) 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.006) tmp = Float64(cos(eps) - cos(x)); elseif (eps <= 0.00165) tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) - Float64(sin(x) * eps)); 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.006) tmp = cos(eps) - cos(x); elseif (eps <= 0.00165) tmp = (-0.5 * (eps * (eps * cos(x)))) - (sin(x) * eps); else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.006], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00165], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * eps), $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.006:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{elif}\;\varepsilon \leq 0.00165:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) - \sin x \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if eps < -0.0060000000000000001Initial program 62.9%
Taylor expanded in x around 0 64.3%
if -0.0060000000000000001 < eps < 0.00165Initial program 15.1%
Taylor expanded in eps around 0 99.2%
mul-1-neg99.2%
unsub-neg99.2%
unpow299.2%
associate-*l*99.2%
Simplified99.2%
if 0.00165 < eps Initial program 50.6%
diff-cos50.6%
div-inv50.6%
metadata-eval50.6%
div-inv50.6%
+-commutative50.6%
metadata-eval50.6%
Applied egg-rr50.6%
*-commutative50.6%
+-commutative50.6%
associate--l+52.6%
+-inverses52.6%
distribute-lft-in52.6%
metadata-eval52.6%
*-commutative52.6%
+-commutative52.6%
Simplified52.6%
Taylor expanded in x around 0 53.2%
Final simplification75.6%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* eps 0.5)) (sin (* 0.5 (+ x (+ x eps)))))))
double code(double x, double eps) {
return -2.0 * (sin((eps * 0.5)) * sin((0.5 * (x + (x + eps)))));
}
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 * (x + (x + eps)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((eps * 0.5)) * Math.sin((0.5 * (x + (x + eps)))));
}
def code(x, eps): return -2.0 * (math.sin((eps * 0.5)) * math.sin((0.5 * (x + (x + eps)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(eps * 0.5)) * sin(Float64(0.5 * Float64(x + Float64(x + eps)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((eps * 0.5)) * sin((0.5 * (x + (x + eps))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(x + N[(x + eps), $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(x + \left(x + \varepsilon\right)\right)\right)\right)
\end{array}
Initial program 38.9%
diff-cos46.2%
div-inv46.2%
metadata-eval46.2%
div-inv46.2%
+-commutative46.2%
metadata-eval46.2%
Applied egg-rr46.2%
*-commutative46.2%
+-commutative46.2%
associate--l+75.0%
+-inverses75.0%
distribute-lft-in75.0%
metadata-eval75.0%
*-commutative75.0%
+-commutative75.0%
Simplified75.0%
Final simplification75.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.1e-51) (not (<= eps 2.5e-26))) (* -2.0 (pow (sin (* eps 0.5)) 2.0)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.1e-51) || !(eps <= 2.5e-26)) {
tmp = -2.0 * pow(sin((eps * 0.5)), 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.1d-51)) .or. (.not. (eps <= 2.5d-26))) then
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 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.1e-51) || !(eps <= 2.5e-26)) {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.1e-51) or not (eps <= 2.5e-26): tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.1e-51) || !(eps <= 2.5e-26)) tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 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.1e-51) || ~((eps <= 2.5e-26))) tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.1e-51], N[Not[LessEqual[eps, 2.5e-26]], $MachinePrecision]], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.1 \cdot 10^{-51} \lor \neg \left(\varepsilon \leq 2.5 \cdot 10^{-26}\right):\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -1.1e-51 or 2.5000000000000001e-26 < eps Initial program 51.1%
diff-cos57.9%
div-inv57.9%
metadata-eval57.9%
div-inv57.9%
+-commutative57.9%
metadata-eval57.9%
Applied egg-rr57.9%
*-commutative57.9%
+-commutative57.9%
associate--l+61.1%
+-inverses61.1%
distribute-lft-in61.1%
metadata-eval61.1%
*-commutative61.1%
+-commutative61.1%
Simplified61.1%
Taylor expanded in x around 0 59.7%
if -1.1e-51 < eps < 2.5000000000000001e-26Initial program 17.1%
Taylor expanded in eps around 0 91.7%
associate-*r*91.7%
mul-1-neg91.7%
Simplified91.7%
Final simplification71.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (cos eps) (cos x))))
(if (<= eps -0.0002)
t_0
(if (<= eps -1.3e-49)
(* eps (* eps -0.5))
(if (<= eps 0.00122) (* (sin x) (- eps)) t_0)))))
double code(double x, double eps) {
double t_0 = cos(eps) - cos(x);
double tmp;
if (eps <= -0.0002) {
tmp = t_0;
} else if (eps <= -1.3e-49) {
tmp = eps * (eps * -0.5);
} else if (eps <= 0.00122) {
tmp = sin(x) * -eps;
} 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) - cos(x)
if (eps <= (-0.0002d0)) then
tmp = t_0
else if (eps <= (-1.3d-49)) then
tmp = eps * (eps * (-0.5d0))
else if (eps <= 0.00122d0) then
tmp = sin(x) * -eps
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(eps) - Math.cos(x);
double tmp;
if (eps <= -0.0002) {
tmp = t_0;
} else if (eps <= -1.3e-49) {
tmp = eps * (eps * -0.5);
} else if (eps <= 0.00122) {
tmp = Math.sin(x) * -eps;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) - math.cos(x) tmp = 0 if eps <= -0.0002: tmp = t_0 elif eps <= -1.3e-49: tmp = eps * (eps * -0.5) elif eps <= 0.00122: tmp = math.sin(x) * -eps else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) - cos(x)) tmp = 0.0 if (eps <= -0.0002) tmp = t_0; elseif (eps <= -1.3e-49) tmp = Float64(eps * Float64(eps * -0.5)); elseif (eps <= 0.00122) tmp = Float64(sin(x) * Float64(-eps)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) - cos(x); tmp = 0.0; if (eps <= -0.0002) tmp = t_0; elseif (eps <= -1.3e-49) tmp = eps * (eps * -0.5); elseif (eps <= 0.00122) tmp = sin(x) * -eps; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.0002], t$95$0, If[LessEqual[eps, -1.3e-49], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00122], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon - \cos x\\
\mathbf{if}\;\varepsilon \leq -0.0002:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -1.3 \cdot 10^{-49}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00122:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -2.0000000000000001e-4 or 0.00121999999999999995 < eps Initial program 56.2%
Taylor expanded in x around 0 58.2%
if -2.0000000000000001e-4 < eps < -1.29999999999999997e-49Initial program 3.6%
Taylor expanded in x around 0 3.6%
Taylor expanded in eps around 0 89.8%
*-commutative89.8%
unpow289.8%
associate-*l*89.8%
Simplified89.8%
if -1.29999999999999997e-49 < eps < 0.00121999999999999995Initial program 16.1%
Taylor expanded in eps around 0 87.1%
associate-*r*87.1%
mul-1-neg87.1%
Simplified87.1%
Final simplification70.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)) (t_1 (* eps (* eps -0.5))))
(if (<= eps -0.00018)
t_0
(if (<= eps -5.8e-142)
t_1
(if (<= eps 7.4e-62) (* x (- eps)) (if (<= eps 9.5e-7) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double t_1 = eps * (eps * -0.5);
double tmp;
if (eps <= -0.00018) {
tmp = t_0;
} else if (eps <= -5.8e-142) {
tmp = t_1;
} else if (eps <= 7.4e-62) {
tmp = x * -eps;
} else if (eps <= 9.5e-7) {
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 = eps * (eps * (-0.5d0))
if (eps <= (-0.00018d0)) then
tmp = t_0
else if (eps <= (-5.8d-142)) then
tmp = t_1
else if (eps <= 7.4d-62) then
tmp = x * -eps
else if (eps <= 9.5d-7) 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 = eps * (eps * -0.5);
double tmp;
if (eps <= -0.00018) {
tmp = t_0;
} else if (eps <= -5.8e-142) {
tmp = t_1;
} else if (eps <= 7.4e-62) {
tmp = x * -eps;
} else if (eps <= 9.5e-7) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 t_1 = eps * (eps * -0.5) tmp = 0 if eps <= -0.00018: tmp = t_0 elif eps <= -5.8e-142: tmp = t_1 elif eps <= 7.4e-62: tmp = x * -eps elif eps <= 9.5e-7: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) t_1 = Float64(eps * Float64(eps * -0.5)) tmp = 0.0 if (eps <= -0.00018) tmp = t_0; elseif (eps <= -5.8e-142) tmp = t_1; elseif (eps <= 7.4e-62) tmp = Float64(x * Float64(-eps)); elseif (eps <= 9.5e-7) 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 = eps * (eps * -0.5); tmp = 0.0; if (eps <= -0.00018) tmp = t_0; elseif (eps <= -5.8e-142) tmp = t_1; elseif (eps <= 7.4e-62) tmp = x * -eps; elseif (eps <= 9.5e-7) 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[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00018], t$95$0, If[LessEqual[eps, -5.8e-142], t$95$1, If[LessEqual[eps, 7.4e-62], N[(x * (-eps)), $MachinePrecision], If[LessEqual[eps, 9.5e-7], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
t_1 := \varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\mathbf{if}\;\varepsilon \leq -0.00018:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -5.8 \cdot 10^{-142}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 7.4 \cdot 10^{-62}:\\
\;\;\;\;x \cdot \left(-\varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 9.5 \cdot 10^{-7}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.80000000000000011e-4 or 9.5000000000000001e-7 < eps Initial program 55.5%
Taylor expanded in x around 0 56.8%
if -1.80000000000000011e-4 < eps < -5.7999999999999998e-142 or 7.3999999999999996e-62 < eps < 9.5000000000000001e-7Initial program 4.1%
Taylor expanded in x around 0 4.1%
Taylor expanded in eps around 0 48.1%
*-commutative48.1%
unpow248.1%
associate-*l*48.1%
Simplified48.1%
if -5.7999999999999998e-142 < eps < 7.3999999999999996e-62Initial program 22.7%
add-log-exp22.0%
Applied egg-rr22.0%
Taylor expanded in eps around 0 98.3%
mul-1-neg98.3%
distribute-lft-neg-out98.3%
*-commutative98.3%
Simplified98.3%
Taylor expanded in x around 0 39.9%
associate-*r*39.9%
neg-mul-139.9%
Simplified39.9%
Final simplification51.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)))
(if (<= eps -0.00018)
t_0
(if (<= eps -2.35e-52)
(* eps (* eps -0.5))
(if (<= eps 0.00125) (* (sin x) (- eps)) t_0)))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double tmp;
if (eps <= -0.00018) {
tmp = t_0;
} else if (eps <= -2.35e-52) {
tmp = eps * (eps * -0.5);
} else if (eps <= 0.00125) {
tmp = sin(x) * -eps;
} 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 <= (-0.00018d0)) then
tmp = t_0
else if (eps <= (-2.35d-52)) then
tmp = eps * (eps * (-0.5d0))
else if (eps <= 0.00125d0) then
tmp = sin(x) * -eps
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 <= -0.00018) {
tmp = t_0;
} else if (eps <= -2.35e-52) {
tmp = eps * (eps * -0.5);
} else if (eps <= 0.00125) {
tmp = Math.sin(x) * -eps;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 tmp = 0 if eps <= -0.00018: tmp = t_0 elif eps <= -2.35e-52: tmp = eps * (eps * -0.5) elif eps <= 0.00125: tmp = math.sin(x) * -eps else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) tmp = 0.0 if (eps <= -0.00018) tmp = t_0; elseif (eps <= -2.35e-52) tmp = Float64(eps * Float64(eps * -0.5)); elseif (eps <= 0.00125) tmp = Float64(sin(x) * Float64(-eps)); 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 <= -0.00018) tmp = t_0; elseif (eps <= -2.35e-52) tmp = eps * (eps * -0.5); elseif (eps <= 0.00125) tmp = sin(x) * -eps; 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, -0.00018], t$95$0, If[LessEqual[eps, -2.35e-52], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00125], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
\mathbf{if}\;\varepsilon \leq -0.00018:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -2.35 \cdot 10^{-52}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00125:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.80000000000000011e-4 or 0.00125000000000000003 < eps Initial program 56.2%
Taylor expanded in x around 0 57.4%
if -1.80000000000000011e-4 < eps < -2.3499999999999999e-52Initial program 3.6%
Taylor expanded in x around 0 3.6%
Taylor expanded in eps around 0 89.8%
*-commutative89.8%
unpow289.8%
associate-*l*89.8%
Simplified89.8%
if -2.3499999999999999e-52 < eps < 0.00125000000000000003Initial program 16.1%
Taylor expanded in eps around 0 87.1%
associate-*r*87.1%
mul-1-neg87.1%
Simplified87.1%
Final simplification70.0%
(FPCore (x eps) :precision binary64 (if (or (<= x -3.4e-65) (not (<= x 2.3e-124))) (* x (- eps)) (* eps (* eps -0.5))))
double code(double x, double eps) {
double tmp;
if ((x <= -3.4e-65) || !(x <= 2.3e-124)) {
tmp = x * -eps;
} 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 ((x <= (-3.4d-65)) .or. (.not. (x <= 2.3d-124))) then
tmp = x * -eps
else
tmp = eps * (eps * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -3.4e-65) || !(x <= 2.3e-124)) {
tmp = x * -eps;
} else {
tmp = eps * (eps * -0.5);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -3.4e-65) or not (x <= 2.3e-124): tmp = x * -eps else: tmp = eps * (eps * -0.5) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -3.4e-65) || !(x <= 2.3e-124)) tmp = Float64(x * Float64(-eps)); else tmp = Float64(eps * Float64(eps * -0.5)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -3.4e-65) || ~((x <= 2.3e-124))) tmp = x * -eps; else tmp = eps * (eps * -0.5); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -3.4e-65], N[Not[LessEqual[x, 2.3e-124]], $MachinePrecision]], N[(x * (-eps)), $MachinePrecision], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{-65} \lor \neg \left(x \leq 2.3 \cdot 10^{-124}\right):\\
\;\;\;\;x \cdot \left(-\varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\end{array}
\end{array}
if x < -3.39999999999999987e-65 or 2.30000000000000012e-124 < x Initial program 19.9%
add-log-exp19.9%
Applied egg-rr19.9%
Taylor expanded in eps around 0 45.6%
mul-1-neg45.6%
distribute-lft-neg-out45.6%
*-commutative45.6%
Simplified45.6%
Taylor expanded in x around 0 12.1%
associate-*r*12.1%
neg-mul-112.1%
Simplified12.1%
if -3.39999999999999987e-65 < x < 2.30000000000000012e-124Initial program 75.9%
Taylor expanded in x around 0 75.9%
Taylor expanded in eps around 0 37.1%
*-commutative37.1%
unpow237.1%
associate-*l*37.1%
Simplified37.1%
Final simplification20.6%
(FPCore (x eps) :precision binary64 (* x (- eps)))
double code(double x, double eps) {
return x * -eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x * -eps
end function
public static double code(double x, double eps) {
return x * -eps;
}
def code(x, eps): return x * -eps
function code(x, eps) return Float64(x * Float64(-eps)) end
function tmp = code(x, eps) tmp = x * -eps; end
code[x_, eps_] := N[(x * (-eps)), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(-\varepsilon\right)
\end{array}
Initial program 38.9%
add-log-exp38.8%
Applied egg-rr38.8%
Taylor expanded in eps around 0 36.5%
mul-1-neg36.5%
distribute-lft-neg-out36.5%
*-commutative36.5%
Simplified36.5%
Taylor expanded in x around 0 14.3%
associate-*r*14.3%
neg-mul-114.3%
Simplified14.3%
Final simplification14.3%
herbie shell --seed 2023229
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))