
(FPCore (x eps) :precision binary64 (- (sin (+ x eps)) (sin x)))
double code(double x, double eps) {
return sin((x + eps)) - sin(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin((x + eps)) - sin(x)
end function
public static double code(double x, double eps) {
return Math.sin((x + eps)) - Math.sin(x);
}
def code(x, eps): return math.sin((x + eps)) - math.sin(x)
function code(x, eps) return Float64(sin(Float64(x + eps)) - sin(x)) end
function tmp = code(x, eps) tmp = sin((x + eps)) - sin(x); end
code[x_, eps_] := N[(N[Sin[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(x + \varepsilon\right) - \sin x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (sin (+ x eps)) (sin x)))
double code(double x, double eps) {
return sin((x + eps)) - sin(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin((x + eps)) - sin(x)
end function
public static double code(double x, double eps) {
return Math.sin((x + eps)) - Math.sin(x);
}
def code(x, eps): return math.sin((x + eps)) - math.sin(x)
function code(x, eps) return Float64(sin(Float64(x + eps)) - sin(x)) end
function tmp = code(x, eps) tmp = sin((x + eps)) - sin(x); end
code[x_, eps_] := N[(N[Sin[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(x + \varepsilon\right) - \sin x
\end{array}
(FPCore (x eps) :precision binary64 (fma (sin x) (+ (cos eps) -1.0) (* (cos x) (sin eps))))
double code(double x, double eps) {
return fma(sin(x), (cos(eps) + -1.0), (cos(x) * sin(eps)));
}
function code(x, eps) return fma(sin(x), Float64(cos(eps) + -1.0), Float64(cos(x) * sin(eps))) end
code[x_, eps_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin x, \cos \varepsilon + -1, \cos x \cdot \sin \varepsilon\right)
\end{array}
Initial program 41.9%
sin-sum65.2%
associate--l+65.1%
Applied egg-rr65.1%
+-commutative65.1%
associate-+l-99.6%
*-commutative99.6%
*-rgt-identity99.6%
distribute-lft-out--99.7%
Simplified99.7%
Taylor expanded in eps around inf 99.7%
sub-neg99.7%
*-commutative99.7%
distribute-rgt-neg-out99.7%
+-commutative99.7%
fma-def99.7%
neg-sub099.7%
associate--r-99.7%
metadata-eval99.7%
+-commutative99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x eps) :precision binary64 (+ (* (cos x) (sin eps)) (* (sin x) (+ (cos eps) -1.0))))
double code(double x, double eps) {
return (cos(x) * sin(eps)) + (sin(x) * (cos(eps) + -1.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (cos(x) * sin(eps)) + (sin(x) * (cos(eps) + (-1.0d0)))
end function
public static double code(double x, double eps) {
return (Math.cos(x) * Math.sin(eps)) + (Math.sin(x) * (Math.cos(eps) + -1.0));
}
def code(x, eps): return (math.cos(x) * math.sin(eps)) + (math.sin(x) * (math.cos(eps) + -1.0))
function code(x, eps) return Float64(Float64(cos(x) * sin(eps)) + Float64(sin(x) * Float64(cos(eps) + -1.0))) end
function tmp = code(x, eps) tmp = (cos(x) * sin(eps)) + (sin(x) * (cos(eps) + -1.0)); end
code[x_, eps_] := N[(N[(N[Cos[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \sin \varepsilon + \sin x \cdot \left(\cos \varepsilon + -1\right)
\end{array}
Initial program 41.9%
sin-sum65.2%
associate--l+65.1%
Applied egg-rr65.1%
+-commutative65.1%
associate-+l-99.6%
*-commutative99.6%
*-rgt-identity99.6%
distribute-lft-out--99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (sin x) (+ (cos eps) -1.0))))
(if (or (<= eps -14200000.0) (not (<= eps 1.55e-10)))
(+ (sin eps) t_0)
(+ (* eps (cos x)) t_0))))
double code(double x, double eps) {
double t_0 = sin(x) * (cos(eps) + -1.0);
double tmp;
if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) {
tmp = sin(eps) + t_0;
} else {
tmp = (eps * cos(x)) + t_0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin(x) * (cos(eps) + (-1.0d0))
if ((eps <= (-14200000.0d0)) .or. (.not. (eps <= 1.55d-10))) then
tmp = sin(eps) + t_0
else
tmp = (eps * cos(x)) + t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin(x) * (Math.cos(eps) + -1.0);
double tmp;
if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) {
tmp = Math.sin(eps) + t_0;
} else {
tmp = (eps * Math.cos(x)) + t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.sin(x) * (math.cos(eps) + -1.0) tmp = 0 if (eps <= -14200000.0) or not (eps <= 1.55e-10): tmp = math.sin(eps) + t_0 else: tmp = (eps * math.cos(x)) + t_0 return tmp
function code(x, eps) t_0 = Float64(sin(x) * Float64(cos(eps) + -1.0)) tmp = 0.0 if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) tmp = Float64(sin(eps) + t_0); else tmp = Float64(Float64(eps * cos(x)) + t_0); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin(x) * (cos(eps) + -1.0); tmp = 0.0; if ((eps <= -14200000.0) || ~((eps <= 1.55e-10))) tmp = sin(eps) + t_0; else tmp = (eps * cos(x)) + t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[eps, -14200000.0], N[Not[LessEqual[eps, 1.55e-10]], $MachinePrecision]], N[(N[Sin[eps], $MachinePrecision] + t$95$0), $MachinePrecision], N[(N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin x \cdot \left(\cos \varepsilon + -1\right)\\
\mathbf{if}\;\varepsilon \leq -14200000 \lor \neg \left(\varepsilon \leq 1.55 \cdot 10^{-10}\right):\\
\;\;\;\;\sin \varepsilon + t_0\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \cos x + t_0\\
\end{array}
\end{array}
if eps < -1.42e7 or 1.55000000000000008e-10 < eps Initial program 54.0%
sin-sum99.4%
associate--l+99.4%
Applied egg-rr99.4%
+-commutative99.4%
associate-+l-99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.6%
Simplified99.6%
Taylor expanded in x around 0 57.3%
if -1.42e7 < eps < 1.55000000000000008e-10Initial program 30.7%
sin-sum33.5%
associate--l+33.5%
Applied egg-rr33.5%
+-commutative33.5%
associate-+l-99.7%
*-commutative99.7%
*-rgt-identity99.7%
distribute-lft-out--99.8%
Simplified99.8%
Taylor expanded in eps around 0 97.6%
Final simplification78.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -14200000.0) (not (<= eps 1.55e-10))) (+ (sin eps) (* (sin x) (+ (cos eps) -1.0))) (* (cos x) (* 2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) {
tmp = sin(eps) + (sin(x) * (cos(eps) + -1.0));
} else {
tmp = cos(x) * (2.0 * sin((eps * 0.5)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-14200000.0d0)) .or. (.not. (eps <= 1.55d-10))) then
tmp = sin(eps) + (sin(x) * (cos(eps) + (-1.0d0)))
else
tmp = cos(x) * (2.0d0 * sin((eps * 0.5d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) {
tmp = Math.sin(eps) + (Math.sin(x) * (Math.cos(eps) + -1.0));
} else {
tmp = Math.cos(x) * (2.0 * Math.sin((eps * 0.5)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -14200000.0) or not (eps <= 1.55e-10): tmp = math.sin(eps) + (math.sin(x) * (math.cos(eps) + -1.0)) else: tmp = math.cos(x) * (2.0 * math.sin((eps * 0.5))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) tmp = Float64(sin(eps) + Float64(sin(x) * Float64(cos(eps) + -1.0))); else tmp = Float64(cos(x) * Float64(2.0 * sin(Float64(eps * 0.5)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -14200000.0) || ~((eps <= 1.55e-10))) tmp = sin(eps) + (sin(x) * (cos(eps) + -1.0)); else tmp = cos(x) * (2.0 * sin((eps * 0.5))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -14200000.0], N[Not[LessEqual[eps, 1.55e-10]], $MachinePrecision]], N[(N[Sin[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[x], $MachinePrecision] * N[(2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -14200000 \lor \neg \left(\varepsilon \leq 1.55 \cdot 10^{-10}\right):\\
\;\;\;\;\sin \varepsilon + \sin x \cdot \left(\cos \varepsilon + -1\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -1.42e7 or 1.55000000000000008e-10 < eps Initial program 54.0%
sin-sum99.4%
associate--l+99.4%
Applied egg-rr99.4%
+-commutative99.4%
associate-+l-99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.6%
Simplified99.6%
Taylor expanded in x around 0 57.3%
if -1.42e7 < eps < 1.55000000000000008e-10Initial program 30.7%
diff-sin30.7%
div-inv30.7%
associate--l+30.7%
metadata-eval30.7%
div-inv30.7%
+-commutative30.7%
associate-+l+30.7%
metadata-eval30.7%
Applied egg-rr30.7%
associate-*r*30.7%
*-commutative30.7%
*-commutative30.7%
+-commutative30.7%
count-230.7%
fma-def30.7%
sub-neg30.7%
mul-1-neg30.7%
+-commutative30.7%
associate-+r+97.6%
mul-1-neg97.6%
sub-neg97.6%
+-inverses97.6%
remove-double-neg97.6%
mul-1-neg97.6%
sub-neg97.6%
neg-sub097.6%
mul-1-neg97.6%
remove-double-neg97.6%
Simplified97.6%
Taylor expanded in eps around 0 97.5%
Final simplification78.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)))
(if (<= eps -3e-8)
(+ (sin eps) (* (sin x) t_0))
(+ (* (cos x) (sin eps)) (* x t_0)))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double tmp;
if (eps <= -3e-8) {
tmp = sin(eps) + (sin(x) * t_0);
} else {
tmp = (cos(x) * sin(eps)) + (x * 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 <= (-3d-8)) then
tmp = sin(eps) + (sin(x) * t_0)
else
tmp = (cos(x) * sin(eps)) + (x * 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 <= -3e-8) {
tmp = Math.sin(eps) + (Math.sin(x) * t_0);
} else {
tmp = (Math.cos(x) * Math.sin(eps)) + (x * t_0);
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 tmp = 0 if eps <= -3e-8: tmp = math.sin(eps) + (math.sin(x) * t_0) else: tmp = (math.cos(x) * math.sin(eps)) + (x * t_0) return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) tmp = 0.0 if (eps <= -3e-8) tmp = Float64(sin(eps) + Float64(sin(x) * t_0)); else tmp = Float64(Float64(cos(x) * sin(eps)) + Float64(x * t_0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) + -1.0; tmp = 0.0; if (eps <= -3e-8) tmp = sin(eps) + (sin(x) * t_0); else tmp = (cos(x) * sin(eps)) + (x * 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, -3e-8], N[(N[Sin[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] + N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
\mathbf{if}\;\varepsilon \leq -3 \cdot 10^{-8}:\\
\;\;\;\;\sin \varepsilon + \sin x \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \sin \varepsilon + x \cdot t_0\\
\end{array}
\end{array}
if eps < -2.99999999999999973e-8Initial program 56.4%
sin-sum99.4%
associate--l+99.3%
Applied egg-rr99.3%
+-commutative99.3%
associate-+l-99.5%
*-commutative99.5%
*-rgt-identity99.5%
distribute-lft-out--99.6%
Simplified99.6%
Taylor expanded in x around 0 59.6%
if -2.99999999999999973e-8 < eps Initial program 35.9%
sin-sum51.0%
associate--l+51.0%
Applied egg-rr51.0%
+-commutative51.0%
associate-+l-99.6%
*-commutative99.6%
*-rgt-identity99.6%
distribute-lft-out--99.7%
Simplified99.7%
Taylor expanded in x around 0 84.2%
Final simplification77.0%
(FPCore (x eps) :precision binary64 (+ (* (cos x) (sin eps)) (* (sin x) 0.0)))
double code(double x, double eps) {
return (cos(x) * sin(eps)) + (sin(x) * 0.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (cos(x) * sin(eps)) + (sin(x) * 0.0d0)
end function
public static double code(double x, double eps) {
return (Math.cos(x) * Math.sin(eps)) + (Math.sin(x) * 0.0);
}
def code(x, eps): return (math.cos(x) * math.sin(eps)) + (math.sin(x) * 0.0)
function code(x, eps) return Float64(Float64(cos(x) * sin(eps)) + Float64(sin(x) * 0.0)) end
function tmp = code(x, eps) tmp = (cos(x) * sin(eps)) + (sin(x) * 0.0); end
code[x_, eps_] := N[(N[(N[Cos[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \sin \varepsilon + \sin x \cdot 0
\end{array}
Initial program 41.9%
sin-sum65.2%
associate--l+65.1%
Applied egg-rr65.1%
+-commutative65.1%
associate-+l-99.6%
*-commutative99.6%
*-rgt-identity99.6%
distribute-lft-out--99.7%
Simplified99.7%
Taylor expanded in eps around 0 78.3%
Final simplification78.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -14200000.0) (not (<= eps 1.55e-10))) (sin eps) (* (cos x) (* 2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) {
tmp = sin(eps);
} else {
tmp = cos(x) * (2.0 * sin((eps * 0.5)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-14200000.0d0)) .or. (.not. (eps <= 1.55d-10))) then
tmp = sin(eps)
else
tmp = cos(x) * (2.0d0 * sin((eps * 0.5d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) {
tmp = Math.sin(eps);
} else {
tmp = Math.cos(x) * (2.0 * Math.sin((eps * 0.5)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -14200000.0) or not (eps <= 1.55e-10): tmp = math.sin(eps) else: tmp = math.cos(x) * (2.0 * math.sin((eps * 0.5))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) tmp = sin(eps); else tmp = Float64(cos(x) * Float64(2.0 * sin(Float64(eps * 0.5)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -14200000.0) || ~((eps <= 1.55e-10))) tmp = sin(eps); else tmp = cos(x) * (2.0 * sin((eps * 0.5))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -14200000.0], N[Not[LessEqual[eps, 1.55e-10]], $MachinePrecision]], N[Sin[eps], $MachinePrecision], N[(N[Cos[x], $MachinePrecision] * N[(2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -14200000 \lor \neg \left(\varepsilon \leq 1.55 \cdot 10^{-10}\right):\\
\;\;\;\;\sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -1.42e7 or 1.55000000000000008e-10 < eps Initial program 54.0%
Taylor expanded in x around 0 55.5%
if -1.42e7 < eps < 1.55000000000000008e-10Initial program 30.7%
diff-sin30.7%
div-inv30.7%
associate--l+30.7%
metadata-eval30.7%
div-inv30.7%
+-commutative30.7%
associate-+l+30.7%
metadata-eval30.7%
Applied egg-rr30.7%
associate-*r*30.7%
*-commutative30.7%
*-commutative30.7%
+-commutative30.7%
count-230.7%
fma-def30.7%
sub-neg30.7%
mul-1-neg30.7%
+-commutative30.7%
associate-+r+97.6%
mul-1-neg97.6%
sub-neg97.6%
+-inverses97.6%
remove-double-neg97.6%
mul-1-neg97.6%
sub-neg97.6%
neg-sub097.6%
mul-1-neg97.6%
remove-double-neg97.6%
Simplified97.6%
Taylor expanded in eps around 0 97.5%
Final simplification77.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -14200000.0) (not (<= eps 1.55e-10))) (sin eps) (* eps (cos x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) {
tmp = sin(eps);
} else {
tmp = 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 <= (-14200000.0d0)) .or. (.not. (eps <= 1.55d-10))) then
tmp = sin(eps)
else
tmp = eps * cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) {
tmp = Math.sin(eps);
} else {
tmp = eps * Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -14200000.0) or not (eps <= 1.55e-10): tmp = math.sin(eps) else: tmp = eps * math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -14200000.0) || !(eps <= 1.55e-10)) tmp = sin(eps); else tmp = Float64(eps * cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -14200000.0) || ~((eps <= 1.55e-10))) tmp = sin(eps); else tmp = eps * cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -14200000.0], N[Not[LessEqual[eps, 1.55e-10]], $MachinePrecision]], N[Sin[eps], $MachinePrecision], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -14200000 \lor \neg \left(\varepsilon \leq 1.55 \cdot 10^{-10}\right):\\
\;\;\;\;\sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\end{array}
\end{array}
if eps < -1.42e7 or 1.55000000000000008e-10 < eps Initial program 54.0%
Taylor expanded in x around 0 55.5%
if -1.42e7 < eps < 1.55000000000000008e-10Initial program 30.7%
Taylor expanded in eps around 0 97.4%
Final simplification77.3%
(FPCore (x eps) :precision binary64 (sin eps))
double code(double x, double eps) {
return sin(eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin(eps)
end function
public static double code(double x, double eps) {
return Math.sin(eps);
}
def code(x, eps): return math.sin(eps)
function code(x, eps) return sin(eps) end
function tmp = code(x, eps) tmp = sin(eps); end
code[x_, eps_] := N[Sin[eps], $MachinePrecision]
\begin{array}{l}
\\
\sin \varepsilon
\end{array}
Initial program 41.9%
Taylor expanded in x around 0 54.7%
Final simplification54.7%
(FPCore (x eps) :precision binary64 eps)
double code(double x, double eps) {
return eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps
end function
public static double code(double x, double eps) {
return eps;
}
def code(x, eps): return eps
function code(x, eps) return eps end
function tmp = code(x, eps) tmp = eps; end
code[x_, eps_] := eps
\begin{array}{l}
\\
\varepsilon
\end{array}
Initial program 41.9%
Taylor expanded in eps around 0 52.7%
Taylor expanded in x around 0 30.3%
Final simplification30.3%
(FPCore (x eps) :precision binary64 (fma (cos x) (sin eps) (* (sin x) (- (cos eps) 1.0))))
double code(double x, double eps) {
return fma(cos(x), sin(eps), (sin(x) * (cos(eps) - 1.0)));
}
function code(x, eps) return fma(cos(x), sin(eps), Float64(sin(x) * Float64(cos(eps) - 1.0))) end
code[x_, eps_] := N[(N[Cos[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos x, \sin \varepsilon, \sin x \cdot \left(\cos \varepsilon - 1\right)\right)
\end{array}
herbie shell --seed 2023313
(FPCore (x eps)
:name "2sin (example 3.3)"
:precision binary64
:herbie-target
(fma (cos x) (sin eps) (* (sin x) (- (cos eps) 1.0)))
(- (sin (+ x eps)) (sin x)))