
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
(FPCore (x eps)
:precision binary64
(if (<= eps -0.0028)
(fma (sin eps) (- (sin x)) (* (cos x) (+ -1.0 (cos eps))))
(if (<= eps 0.0034)
(fma
0.041666666666666664
(* (cos x) (pow eps 4.0))
(+
(* -0.5 (* eps (* eps (cos x))))
(* (sin x) (- (* 0.16666666666666666 (pow eps 3.0)) eps))))
(- (fma (cos x) (cos eps) (* (sin x) (- (sin eps)))) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0028) {
tmp = fma(sin(eps), -sin(x), (cos(x) * (-1.0 + cos(eps))));
} else if (eps <= 0.0034) {
tmp = fma(0.041666666666666664, (cos(x) * pow(eps, 4.0)), ((-0.5 * (eps * (eps * cos(x)))) + (sin(x) * ((0.16666666666666666 * pow(eps, 3.0)) - eps))));
} 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.0028) tmp = fma(sin(eps), Float64(-sin(x)), Float64(cos(x) * Float64(-1.0 + cos(eps)))); elseif (eps <= 0.0034) tmp = fma(0.041666666666666664, Float64(cos(x) * (eps ^ 4.0)), Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) + Float64(sin(x) * Float64(Float64(0.16666666666666666 * (eps ^ 3.0)) - eps)))); 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.0028], N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.0034], N[(0.041666666666666664 * N[(N[Cos[x], $MachinePrecision] * N[Power[eps, 4.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision] - eps), $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.0028:\\
\;\;\;\;\mathsf{fma}\left(\sin \varepsilon, -\sin x, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.0034:\\
\;\;\;\;\mathsf{fma}\left(0.041666666666666664, \cos x \cdot {\varepsilon}^{4}, -0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) + \sin x \cdot \left(0.16666666666666666 \cdot {\varepsilon}^{3} - \varepsilon\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 < -0.00279999999999999997Initial program 64.8%
add-sqr-sqrt29.8%
sqrt-unprod39.1%
pow239.1%
Applied egg-rr39.1%
sqrt-pow164.8%
metadata-eval64.8%
cos-sum99.0%
pow199.0%
fma-neg98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 99.0%
associate--l+98.9%
*-commutative98.9%
associate-*r*98.9%
neg-mul-198.9%
*-commutative98.9%
fma-def99.0%
*-rgt-identity99.0%
distribute-lft-out--99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
if -0.00279999999999999997 < eps < 0.00339999999999999981Initial program 21.9%
Taylor expanded in eps around 0 99.8%
fma-def99.8%
*-commutative99.8%
+-commutative99.8%
associate-+l+99.8%
unpow299.8%
associate-*l*99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
mul-1-neg99.8%
Simplified99.8%
if 0.00339999999999999981 < eps Initial program 51.7%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def99.0%
Applied egg-rr99.0%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= x -1.9e-14) (not (<= x 3e-59))) (fma (sin eps) (- (sin x)) (* (cos x) (+ -1.0 (cos eps)))) (* -2.0 (* (sin (* 0.5 (- eps (* x -2.0)))) (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((x <= -1.9e-14) || !(x <= 3e-59)) {
tmp = fma(sin(eps), -sin(x), (cos(x) * (-1.0 + cos(eps))));
} else {
tmp = -2.0 * (sin((0.5 * (eps - (x * -2.0)))) * sin((eps * 0.5)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((x <= -1.9e-14) || !(x <= 3e-59)) tmp = fma(sin(eps), Float64(-sin(x)), Float64(cos(x) * Float64(-1.0 + cos(eps)))); else tmp = Float64(-2.0 * Float64(sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))) * sin(Float64(eps * 0.5)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[x, -1.9e-14], N[Not[LessEqual[x, 3e-59]], $MachinePrecision]], N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision]) + N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[Sin[N[(0.5 * N[(eps - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{-14} \lor \neg \left(x \leq 3 \cdot 10^{-59}\right):\\
\;\;\;\;\mathsf{fma}\left(\sin \varepsilon, -\sin x, \cos x \cdot \left(-1 + \cos \varepsilon\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\sin \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if x < -1.9000000000000001e-14 or 3.0000000000000001e-59 < x Initial program 14.9%
add-sqr-sqrt7.9%
sqrt-unprod12.5%
pow212.5%
Applied egg-rr12.5%
sqrt-pow114.9%
metadata-eval14.9%
cos-sum53.9%
pow153.9%
fma-neg53.9%
*-commutative53.9%
distribute-rgt-neg-in53.9%
Applied egg-rr53.9%
Taylor expanded in x around inf 53.9%
associate--l+99.2%
*-commutative99.2%
associate-*r*99.2%
neg-mul-199.2%
*-commutative99.2%
fma-def99.2%
*-rgt-identity99.2%
distribute-lft-out--99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
Simplified99.2%
if -1.9000000000000001e-14 < x < 3.0000000000000001e-59Initial program 74.0%
diff-cos93.5%
div-inv93.5%
metadata-eval93.5%
div-inv93.5%
+-commutative93.5%
metadata-eval93.5%
Applied egg-rr93.5%
*-commutative93.5%
+-commutative93.5%
associate--l+99.6%
+-inverses99.6%
distribute-lft-in99.6%
metadata-eval99.6%
*-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around -inf 99.6%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0105) (not (<= eps 0.0105))) (- (cos eps) (cos x)) (- (* -0.5 (* eps (* eps (cos x)))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0105) || !(eps <= 0.0105)) {
tmp = cos(eps) - cos(x);
} else {
tmp = (-0.5 * (eps * (eps * cos(x)))) - (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.0105d0)) .or. (.not. (eps <= 0.0105d0))) then
tmp = cos(eps) - cos(x)
else
tmp = ((-0.5d0) * (eps * (eps * cos(x)))) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0105) || !(eps <= 0.0105)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = (-0.5 * (eps * (eps * Math.cos(x)))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0105) or not (eps <= 0.0105): tmp = math.cos(eps) - math.cos(x) else: tmp = (-0.5 * (eps * (eps * math.cos(x)))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0105) || !(eps <= 0.0105)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(Float64(-0.5 * Float64(eps * Float64(eps * cos(x)))) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0105) || ~((eps <= 0.0105))) tmp = cos(eps) - cos(x); else tmp = (-0.5 * (eps * (eps * cos(x)))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0105], N[Not[LessEqual[eps, 0.0105]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(eps * N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0105 \lor \neg \left(\varepsilon \leq 0.0105\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot \cos x\right)\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -0.0105000000000000007 or 0.0105000000000000007 < eps Initial program 58.6%
Taylor expanded in x around 0 60.8%
if -0.0105000000000000007 < eps < 0.0105000000000000007Initial program 21.9%
Taylor expanded in eps around 0 99.3%
mul-1-neg99.3%
unsub-neg99.3%
unpow299.3%
associate-*l*99.3%
Simplified99.3%
Final simplification79.0%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 (- eps (* x -2.0)))) (sin (* eps 0.5)))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * (eps - (x * -2.0)))) * sin((eps * 0.5)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((0.5d0 * (eps - (x * (-2.0d0))))) * sin((eps * 0.5d0)))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * (eps - (x * -2.0)))) * Math.sin((eps * 0.5)));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * (eps - (x * -2.0)))) * math.sin((eps * 0.5)))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * Float64(eps - Float64(x * -2.0)))) * sin(Float64(eps * 0.5)))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * (eps - (x * -2.0)))) * sin((eps * 0.5))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * N[(eps - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 41.2%
diff-cos49.2%
div-inv49.2%
metadata-eval49.2%
div-inv49.2%
+-commutative49.2%
metadata-eval49.2%
Applied egg-rr49.2%
*-commutative49.2%
+-commutative49.2%
associate--l+77.9%
+-inverses77.9%
distribute-lft-in77.9%
metadata-eval77.9%
*-commutative77.9%
+-commutative77.9%
Simplified77.9%
Taylor expanded in x around -inf 77.9%
Final simplification77.9%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* eps 0.5)) (sin (* 0.5 (+ x (+ eps x)))))))
double code(double x, double eps) {
return -2.0 * (sin((eps * 0.5)) * sin((0.5 * (x + (eps + x)))));
}
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 + (eps + x)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((eps * 0.5)) * Math.sin((0.5 * (x + (eps + x)))));
}
def code(x, eps): return -2.0 * (math.sin((eps * 0.5)) * math.sin((0.5 * (x + (eps + x)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(eps * 0.5)) * sin(Float64(0.5 * Float64(x + Float64(eps + x)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((eps * 0.5)) * sin((0.5 * (x + (eps + x))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(x + N[(eps + x), $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(\varepsilon + x\right)\right)\right)\right)
\end{array}
Initial program 41.2%
diff-cos49.2%
div-inv49.2%
metadata-eval49.2%
div-inv49.2%
+-commutative49.2%
metadata-eval49.2%
Applied egg-rr49.2%
*-commutative49.2%
+-commutative49.2%
associate--l+77.9%
+-inverses77.9%
distribute-lft-in77.9%
metadata-eval77.9%
*-commutative77.9%
+-commutative77.9%
Simplified77.9%
Final simplification77.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (or (<= x -1.2e-16) (not (<= x 1.8e-21)))
(* t_0 (* (sin x) -2.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 <= -1.2e-16) || !(x <= 1.8e-21)) {
tmp = t_0 * (sin(x) * -2.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 <= (-1.2d-16)) .or. (.not. (x <= 1.8d-21))) then
tmp = t_0 * (sin(x) * (-2.0d0))
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 <= -1.2e-16) || !(x <= 1.8e-21)) {
tmp = t_0 * (Math.sin(x) * -2.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 <= -1.2e-16) or not (x <= 1.8e-21): tmp = t_0 * (math.sin(x) * -2.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 <= -1.2e-16) || !(x <= 1.8e-21)) tmp = Float64(t_0 * Float64(sin(x) * -2.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 <= -1.2e-16) || ~((x <= 1.8e-21))) tmp = t_0 * (sin(x) * -2.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, -1.2e-16], N[Not[LessEqual[x, 1.8e-21]], $MachinePrecision]], N[(t$95$0 * N[(N[Sin[x], $MachinePrecision] * -2.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 -1.2 \cdot 10^{-16} \lor \neg \left(x \leq 1.8 \cdot 10^{-21}\right):\\
\;\;\;\;t_0 \cdot \left(\sin x \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -1.20000000000000002e-16 or 1.79999999999999995e-21 < x Initial program 8.8%
diff-cos7.5%
div-inv7.5%
metadata-eval7.5%
div-inv7.5%
+-commutative7.5%
metadata-eval7.5%
Applied egg-rr7.5%
*-commutative7.5%
+-commutative7.5%
associate--l+57.9%
+-inverses57.9%
distribute-lft-in57.9%
metadata-eval57.9%
*-commutative57.9%
+-commutative57.9%
Simplified57.9%
expm1-log1p-u57.9%
*-commutative57.9%
+-commutative57.9%
+-rgt-identity57.9%
Applied egg-rr57.9%
Taylor expanded in eps around 0 56.6%
Taylor expanded in x around inf 56.6%
*-commutative56.6%
associate-*r*56.6%
Simplified56.6%
if -1.20000000000000002e-16 < x < 1.79999999999999995e-21Initial program 76.3%
diff-cos94.2%
div-inv94.2%
metadata-eval94.2%
div-inv94.2%
+-commutative94.2%
metadata-eval94.2%
Applied egg-rr94.2%
*-commutative94.2%
+-commutative94.2%
associate--l+99.5%
+-inverses99.5%
distribute-lft-in99.5%
metadata-eval99.5%
*-commutative99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in x around 0 93.5%
Final simplification74.3%
(FPCore (x eps) :precision binary64 (if (or (<= x -3.2e-15) (not (<= x 8.5e-25))) (* (sin x) (- eps)) (* -2.0 (pow (sin (* eps 0.5)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -3.2e-15) || !(x <= 8.5e-25)) {
tmp = 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 ((x <= (-3.2d-15)) .or. (.not. (x <= 8.5d-25))) then
tmp = 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 ((x <= -3.2e-15) || !(x <= 8.5e-25)) {
tmp = 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 (x <= -3.2e-15) or not (x <= 8.5e-25): tmp = 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 ((x <= -3.2e-15) || !(x <= 8.5e-25)) tmp = Float64(sin(x) * Float64(-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 ((x <= -3.2e-15) || ~((x <= 8.5e-25))) tmp = sin(x) * -eps; else tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -3.2e-15], N[Not[LessEqual[x, 8.5e-25]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * (-eps)), $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}\;x \leq -3.2 \cdot 10^{-15} \lor \neg \left(x \leq 8.5 \cdot 10^{-25}\right):\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\end{array}
\end{array}
if x < -3.1999999999999999e-15 or 8.49999999999999981e-25 < x Initial program 8.8%
Taylor expanded in eps around 0 53.5%
associate-*r*53.5%
mul-1-neg53.5%
Simplified53.5%
if -3.1999999999999999e-15 < x < 8.49999999999999981e-25Initial program 76.3%
diff-cos94.2%
div-inv94.2%
metadata-eval94.2%
div-inv94.2%
+-commutative94.2%
metadata-eval94.2%
Applied egg-rr94.2%
*-commutative94.2%
+-commutative94.2%
associate--l+99.5%
+-inverses99.5%
distribute-lft-in99.5%
metadata-eval99.5%
*-commutative99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in x around 0 93.5%
Final simplification72.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -5.3e-8) (not (<= eps 0.000114))) (- (cos eps) (cos x)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -5.3e-8) || !(eps <= 0.000114)) {
tmp = cos(eps) - cos(x);
} 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 <= (-5.3d-8)) .or. (.not. (eps <= 0.000114d0))) then
tmp = cos(eps) - cos(x)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -5.3e-8) || !(eps <= 0.000114)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -5.3e-8) or not (eps <= 0.000114): tmp = math.cos(eps) - math.cos(x) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -5.3e-8) || !(eps <= 0.000114)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -5.3e-8) || ~((eps <= 0.000114))) tmp = cos(eps) - cos(x); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -5.3e-8], N[Not[LessEqual[eps, 0.000114]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5.3 \cdot 10^{-8} \lor \neg \left(\varepsilon \leq 0.000114\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -5.2999999999999998e-8 or 1.1400000000000001e-4 < eps Initial program 58.5%
Taylor expanded in x around 0 60.7%
if -5.2999999999999998e-8 < eps < 1.1400000000000001e-4Initial program 21.6%
Taylor expanded in eps around 0 81.7%
associate-*r*81.7%
mul-1-neg81.7%
Simplified81.7%
Final simplification70.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (* eps (* eps -0.5))))
(if (<= eps -0.00017)
t_0
(if (<= eps -7.9e-156)
t_1
(if (<= eps 3.1e-87) (* x (- eps)) (if (<= eps 0.00015) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = eps * (eps * -0.5);
double tmp;
if (eps <= -0.00017) {
tmp = t_0;
} else if (eps <= -7.9e-156) {
tmp = t_1;
} else if (eps <= 3.1e-87) {
tmp = x * -eps;
} else if (eps <= 0.00015) {
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 = (-1.0d0) + cos(eps)
t_1 = eps * (eps * (-0.5d0))
if (eps <= (-0.00017d0)) then
tmp = t_0
else if (eps <= (-7.9d-156)) then
tmp = t_1
else if (eps <= 3.1d-87) then
tmp = x * -eps
else if (eps <= 0.00015d0) 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 = -1.0 + Math.cos(eps);
double t_1 = eps * (eps * -0.5);
double tmp;
if (eps <= -0.00017) {
tmp = t_0;
} else if (eps <= -7.9e-156) {
tmp = t_1;
} else if (eps <= 3.1e-87) {
tmp = x * -eps;
} else if (eps <= 0.00015) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) t_1 = eps * (eps * -0.5) tmp = 0 if eps <= -0.00017: tmp = t_0 elif eps <= -7.9e-156: tmp = t_1 elif eps <= 3.1e-87: tmp = x * -eps elif eps <= 0.00015: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(eps * Float64(eps * -0.5)) tmp = 0.0 if (eps <= -0.00017) tmp = t_0; elseif (eps <= -7.9e-156) tmp = t_1; elseif (eps <= 3.1e-87) tmp = Float64(x * Float64(-eps)); elseif (eps <= 0.00015) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = -1.0 + cos(eps); t_1 = eps * (eps * -0.5); tmp = 0.0; if (eps <= -0.00017) tmp = t_0; elseif (eps <= -7.9e-156) tmp = t_1; elseif (eps <= 3.1e-87) tmp = x * -eps; elseif (eps <= 0.00015) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00017], t$95$0, If[LessEqual[eps, -7.9e-156], t$95$1, If[LessEqual[eps, 3.1e-87], N[(x * (-eps)), $MachinePrecision], If[LessEqual[eps, 0.00015], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := \varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\mathbf{if}\;\varepsilon \leq -0.00017:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -7.9 \cdot 10^{-156}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 3.1 \cdot 10^{-87}:\\
\;\;\;\;x \cdot \left(-\varepsilon\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00015:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.7e-4 or 1.49999999999999987e-4 < eps Initial program 58.6%
Taylor expanded in x around 0 58.7%
if -1.7e-4 < eps < -7.89999999999999976e-156 or 3.09999999999999998e-87 < eps < 1.49999999999999987e-4Initial program 5.1%
Taylor expanded in x around 0 5.4%
Taylor expanded in eps around 0 46.8%
*-commutative46.8%
unpow246.8%
associate-*l*46.8%
Simplified46.8%
if -7.89999999999999976e-156 < eps < 3.09999999999999998e-87Initial program 31.4%
Taylor expanded in x around 0 29.9%
Taylor expanded in eps around 0 42.8%
associate-*r*42.8%
mul-1-neg42.8%
Simplified42.8%
Final simplification51.9%
(FPCore (x eps) :precision binary64 (if (or (<= eps -5.5e-8) (not (<= eps 0.000114))) (+ -1.0 (cos eps)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -5.5e-8) || !(eps <= 0.000114)) {
tmp = -1.0 + cos(eps);
} 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 <= (-5.5d-8)) .or. (.not. (eps <= 0.000114d0))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -5.5e-8) || !(eps <= 0.000114)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -5.5e-8) or not (eps <= 0.000114): tmp = -1.0 + math.cos(eps) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -5.5e-8) || !(eps <= 0.000114)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -5.5e-8) || ~((eps <= 0.000114))) tmp = -1.0 + cos(eps); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -5.5e-8], N[Not[LessEqual[eps, 0.000114]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5.5 \cdot 10^{-8} \lor \neg \left(\varepsilon \leq 0.000114\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -5.5000000000000003e-8 or 1.1400000000000001e-4 < eps Initial program 58.5%
Taylor expanded in x around 0 58.6%
if -5.5000000000000003e-8 < eps < 1.1400000000000001e-4Initial program 21.6%
Taylor expanded in eps around 0 81.7%
associate-*r*81.7%
mul-1-neg81.7%
Simplified81.7%
Final simplification69.4%
(FPCore (x eps) :precision binary64 (if (<= x 1.7e-72) (* eps (* eps -0.5)) (* x (- eps))))
double code(double x, double eps) {
double tmp;
if (x <= 1.7e-72) {
tmp = eps * (eps * -0.5);
} else {
tmp = x * -eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 1.7d-72) then
tmp = eps * (eps * (-0.5d0))
else
tmp = x * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 1.7e-72) {
tmp = eps * (eps * -0.5);
} else {
tmp = x * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 1.7e-72: tmp = eps * (eps * -0.5) else: tmp = x * -eps return tmp
function code(x, eps) tmp = 0.0 if (x <= 1.7e-72) tmp = Float64(eps * Float64(eps * -0.5)); else tmp = Float64(x * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 1.7e-72) tmp = eps * (eps * -0.5); else tmp = x * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 1.7e-72], N[(eps * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision], N[(x * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7 \cdot 10^{-72}:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if x < 1.6999999999999999e-72Initial program 49.1%
Taylor expanded in x around 0 49.1%
Taylor expanded in eps around 0 27.2%
*-commutative27.2%
unpow227.2%
associate-*l*27.2%
Simplified27.2%
if 1.6999999999999999e-72 < x Initial program 23.7%
Taylor expanded in x around 0 21.9%
Taylor expanded in eps around 0 11.0%
associate-*r*11.0%
mul-1-neg11.0%
Simplified11.0%
Final simplification22.2%
(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 41.2%
Taylor expanded in x around 0 39.7%
Taylor expanded in eps around 0 16.2%
associate-*r*16.2%
mul-1-neg16.2%
Simplified16.2%
Final simplification16.2%
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
return 0.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
public static double code(double x, double eps) {
return 0.0;
}
def code(x, eps): return 0.0
function code(x, eps) return 0.0 end
function tmp = code(x, eps) tmp = 0.0; end
code[x_, eps_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 41.2%
Taylor expanded in x around 0 41.3%
Taylor expanded in eps around 0 11.8%
Final simplification11.8%
herbie shell --seed 2023240
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))