
(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 12 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) (* (sin eps) (cos x))))
double code(double x, double eps) {
return fma(sin(x), (cos(eps) + -1.0), (sin(eps) * cos(x)));
}
function code(x, eps) return fma(sin(x), Float64(cos(eps) + -1.0), Float64(sin(eps) * cos(x))) end
code[x_, eps_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin x, \cos \varepsilon + -1, \sin \varepsilon \cdot \cos x\right)
\end{array}
Initial program 43.8%
sin-sum69.6%
associate--l+69.5%
Applied egg-rr69.5%
+-commutative69.5%
associate-+l-99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.4%
Simplified99.4%
Taylor expanded in eps around inf 99.4%
fma-neg99.4%
distribute-rgt-neg-in99.4%
neg-sub099.4%
associate--r-99.4%
metadata-eval99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in x around inf 99.4%
+-commutative99.4%
sub-neg99.4%
metadata-eval99.4%
fma-def99.4%
*-commutative99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (+ x eps))) (t_1 (- t_0 (sin x))))
(if (<= t_1 -0.02)
t_1
(if (<= t_1 0.0)
(* (cos x) (* 2.0 (sin (* eps 0.5))))
(- (fabs t_0) (sin x))))))
double code(double x, double eps) {
double t_0 = sin((x + eps));
double t_1 = t_0 - sin(x);
double tmp;
if (t_1 <= -0.02) {
tmp = t_1;
} else if (t_1 <= 0.0) {
tmp = cos(x) * (2.0 * sin((eps * 0.5)));
} else {
tmp = fabs(t_0) - sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = sin((x + eps))
t_1 = t_0 - sin(x)
if (t_1 <= (-0.02d0)) then
tmp = t_1
else if (t_1 <= 0.0d0) then
tmp = cos(x) * (2.0d0 * sin((eps * 0.5d0)))
else
tmp = abs(t_0) - sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((x + eps));
double t_1 = t_0 - Math.sin(x);
double tmp;
if (t_1 <= -0.02) {
tmp = t_1;
} else if (t_1 <= 0.0) {
tmp = Math.cos(x) * (2.0 * Math.sin((eps * 0.5)));
} else {
tmp = Math.abs(t_0) - Math.sin(x);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((x + eps)) t_1 = t_0 - math.sin(x) tmp = 0 if t_1 <= -0.02: tmp = t_1 elif t_1 <= 0.0: tmp = math.cos(x) * (2.0 * math.sin((eps * 0.5))) else: tmp = math.fabs(t_0) - math.sin(x) return tmp
function code(x, eps) t_0 = sin(Float64(x + eps)) t_1 = Float64(t_0 - sin(x)) tmp = 0.0 if (t_1 <= -0.02) tmp = t_1; elseif (t_1 <= 0.0) tmp = Float64(cos(x) * Float64(2.0 * sin(Float64(eps * 0.5)))); else tmp = Float64(abs(t_0) - sin(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((x + eps)); t_1 = t_0 - sin(x); tmp = 0.0; if (t_1 <= -0.02) tmp = t_1; elseif (t_1 <= 0.0) tmp = cos(x) * (2.0 * sin((eps * 0.5))); else tmp = abs(t_0) - sin(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(x + eps), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.02], t$95$1, If[LessEqual[t$95$1, 0.0], N[(N[Cos[x], $MachinePrecision] * N[(2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Abs[t$95$0], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x + \varepsilon\right)\\
t_1 := t_0 - \sin x\\
\mathbf{if}\;t_1 \leq -0.02:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\cos x \cdot \left(2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left|t_0\right| - \sin x\\
\end{array}
\end{array}
if (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < -0.0200000000000000004Initial program 69.3%
if -0.0200000000000000004 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < 0.0Initial program 14.3%
diff-sin14.3%
div-inv14.3%
associate--l+14.3%
metadata-eval14.3%
div-inv14.3%
+-commutative14.3%
associate-+l+14.3%
metadata-eval14.3%
Applied egg-rr14.3%
associate-*r*14.3%
*-commutative14.3%
*-commutative14.3%
+-commutative14.3%
count-214.3%
fma-def14.3%
sub-neg14.3%
mul-1-neg14.3%
+-commutative14.3%
associate-+r+77.0%
mul-1-neg77.0%
sub-neg77.0%
+-inverses77.0%
remove-double-neg77.0%
mul-1-neg77.0%
sub-neg77.0%
neg-sub077.0%
mul-1-neg77.0%
remove-double-neg77.0%
Simplified77.0%
Taylor expanded in eps around 0 77.0%
if 0.0 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) Initial program 76.2%
add-sqr-sqrt73.6%
sqrt-unprod71.6%
pow271.6%
Applied egg-rr71.6%
add-sqr-sqrt71.1%
sqrt-prod71.6%
rem-sqrt-square71.6%
sqrt-pow176.6%
metadata-eval76.6%
pow176.6%
+-commutative76.6%
Applied egg-rr76.6%
Final simplification75.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (+ x eps))) (t_1 (- t_0 (sin x))))
(if (<= t_1 -0.02)
t_1
(if (<= t_1 1e-39) (* (cos x) (* 2.0 (sin (* eps 0.5)))) (fabs t_0)))))
double code(double x, double eps) {
double t_0 = sin((x + eps));
double t_1 = t_0 - sin(x);
double tmp;
if (t_1 <= -0.02) {
tmp = t_1;
} else if (t_1 <= 1e-39) {
tmp = cos(x) * (2.0 * sin((eps * 0.5)));
} else {
tmp = fabs(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 = sin((x + eps))
t_1 = t_0 - sin(x)
if (t_1 <= (-0.02d0)) then
tmp = t_1
else if (t_1 <= 1d-39) then
tmp = cos(x) * (2.0d0 * sin((eps * 0.5d0)))
else
tmp = abs(t_0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((x + eps));
double t_1 = t_0 - Math.sin(x);
double tmp;
if (t_1 <= -0.02) {
tmp = t_1;
} else if (t_1 <= 1e-39) {
tmp = Math.cos(x) * (2.0 * Math.sin((eps * 0.5)));
} else {
tmp = Math.abs(t_0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((x + eps)) t_1 = t_0 - math.sin(x) tmp = 0 if t_1 <= -0.02: tmp = t_1 elif t_1 <= 1e-39: tmp = math.cos(x) * (2.0 * math.sin((eps * 0.5))) else: tmp = math.fabs(t_0) return tmp
function code(x, eps) t_0 = sin(Float64(x + eps)) t_1 = Float64(t_0 - sin(x)) tmp = 0.0 if (t_1 <= -0.02) tmp = t_1; elseif (t_1 <= 1e-39) tmp = Float64(cos(x) * Float64(2.0 * sin(Float64(eps * 0.5)))); else tmp = abs(t_0); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((x + eps)); t_1 = t_0 - sin(x); tmp = 0.0; if (t_1 <= -0.02) tmp = t_1; elseif (t_1 <= 1e-39) tmp = cos(x) * (2.0 * sin((eps * 0.5))); else tmp = abs(t_0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(x + eps), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.02], t$95$1, If[LessEqual[t$95$1, 1e-39], N[(N[Cos[x], $MachinePrecision] * N[(2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Abs[t$95$0], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x + \varepsilon\right)\\
t_1 := t_0 - \sin x\\
\mathbf{if}\;t_1 \leq -0.02:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_1 \leq 10^{-39}:\\
\;\;\;\;\cos x \cdot \left(2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left|t_0\right|\\
\end{array}
\end{array}
if (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < -0.0200000000000000004Initial program 69.3%
if -0.0200000000000000004 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < 9.99999999999999929e-40Initial program 22.7%
diff-sin22.7%
div-inv22.7%
associate--l+22.7%
metadata-eval22.7%
div-inv22.7%
+-commutative22.7%
associate-+l+22.7%
metadata-eval22.7%
Applied egg-rr22.7%
associate-*r*22.7%
*-commutative22.7%
*-commutative22.7%
+-commutative22.7%
count-222.7%
fma-def22.7%
sub-neg22.7%
mul-1-neg22.7%
+-commutative22.7%
associate-+r+79.3%
mul-1-neg79.3%
sub-neg79.3%
+-inverses79.3%
remove-double-neg79.3%
mul-1-neg79.3%
sub-neg79.3%
neg-sub079.3%
mul-1-neg79.3%
remove-double-neg79.3%
Simplified79.3%
Taylor expanded in eps around 0 79.3%
if 9.99999999999999929e-40 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) Initial program 70.7%
add-sqr-sqrt67.7%
sqrt-unprod71.3%
pow271.3%
Applied egg-rr71.3%
add-sqr-sqrt70.8%
sqrt-prod71.3%
rem-sqrt-square71.3%
sqrt-pow171.3%
metadata-eval71.3%
pow171.3%
+-commutative71.3%
Applied egg-rr71.3%
Taylor expanded in x around 0 71.1%
Final simplification75.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}
Initial program 43.8%
sin-sum69.6%
associate--l+69.5%
Applied egg-rr69.5%
+-commutative69.5%
associate-+l-99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.4%
Simplified99.4%
Taylor expanded in eps around inf 99.4%
fma-neg99.4%
distribute-rgt-neg-in99.4%
neg-sub099.4%
associate--r-99.4%
metadata-eval99.4%
+-commutative99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (- (* (sin eps) (cos x)) (* (sin x) (- 1.0 (cos eps)))))
double code(double x, double eps) {
return (sin(eps) * cos(x)) - (sin(x) * (1.0 - cos(eps)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (sin(eps) * cos(x)) - (sin(x) * (1.0d0 - cos(eps)))
end function
public static double code(double x, double eps) {
return (Math.sin(eps) * Math.cos(x)) - (Math.sin(x) * (1.0 - Math.cos(eps)));
}
def code(x, eps): return (math.sin(eps) * math.cos(x)) - (math.sin(x) * (1.0 - math.cos(eps)))
function code(x, eps) return Float64(Float64(sin(eps) * cos(x)) - Float64(sin(x) * Float64(1.0 - cos(eps)))) end
function tmp = code(x, eps) tmp = (sin(eps) * cos(x)) - (sin(x) * (1.0 - cos(eps))); end
code[x_, eps_] := N[(N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[(1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \varepsilon \cdot \cos x - \sin x \cdot \left(1 - \cos \varepsilon\right)
\end{array}
Initial program 43.8%
sin-sum69.6%
associate--l+69.5%
Applied egg-rr69.5%
+-commutative69.5%
associate-+l-99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (sin x) (- 1.0 (cos eps)))))
(if (or (<= eps -0.0062) (not (<= eps 0.00185)))
(- (sin eps) t_0)
(- (* eps (cos x)) t_0))))
double code(double x, double eps) {
double t_0 = sin(x) * (1.0 - cos(eps));
double tmp;
if ((eps <= -0.0062) || !(eps <= 0.00185)) {
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) * (1.0d0 - cos(eps))
if ((eps <= (-0.0062d0)) .or. (.not. (eps <= 0.00185d0))) 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) * (1.0 - Math.cos(eps));
double tmp;
if ((eps <= -0.0062) || !(eps <= 0.00185)) {
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) * (1.0 - math.cos(eps)) tmp = 0 if (eps <= -0.0062) or not (eps <= 0.00185): 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(1.0 - cos(eps))) tmp = 0.0 if ((eps <= -0.0062) || !(eps <= 0.00185)) 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) * (1.0 - cos(eps)); tmp = 0.0; if ((eps <= -0.0062) || ~((eps <= 0.00185))) 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[(1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[eps, -0.0062], N[Not[LessEqual[eps, 0.00185]], $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(1 - \cos \varepsilon\right)\\
\mathbf{if}\;\varepsilon \leq -0.0062 \lor \neg \left(\varepsilon \leq 0.00185\right):\\
\;\;\;\;\sin \varepsilon - t_0\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \cos x - t_0\\
\end{array}
\end{array}
if eps < -0.00619999999999999978 or 0.0018500000000000001 < eps Initial program 54.8%
sin-sum99.4%
associate--l+99.3%
Applied egg-rr99.3%
+-commutative99.3%
associate-+l-99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.4%
Simplified99.4%
Taylor expanded in x around 0 59.4%
if -0.00619999999999999978 < eps < 0.0018500000000000001Initial program 29.7%
sin-sum31.2%
associate--l+31.2%
Applied egg-rr31.2%
+-commutative31.2%
associate-+l-99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.4%
Simplified99.4%
Taylor expanded in eps around 0 98.7%
Final simplification76.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.32e-5) (not (<= eps 0.00185))) (- (sin eps) (* (sin x) (- 1.0 (cos eps)))) (* (cos x) (* 2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.32e-5) || !(eps <= 0.00185)) {
tmp = sin(eps) - (sin(x) * (1.0 - cos(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 <= (-1.32d-5)) .or. (.not. (eps <= 0.00185d0))) then
tmp = sin(eps) - (sin(x) * (1.0d0 - cos(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 <= -1.32e-5) || !(eps <= 0.00185)) {
tmp = Math.sin(eps) - (Math.sin(x) * (1.0 - Math.cos(eps)));
} else {
tmp = Math.cos(x) * (2.0 * Math.sin((eps * 0.5)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.32e-5) or not (eps <= 0.00185): tmp = math.sin(eps) - (math.sin(x) * (1.0 - math.cos(eps))) else: tmp = math.cos(x) * (2.0 * math.sin((eps * 0.5))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.32e-5) || !(eps <= 0.00185)) tmp = Float64(sin(eps) - Float64(sin(x) * Float64(1.0 - cos(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 <= -1.32e-5) || ~((eps <= 0.00185))) tmp = sin(eps) - (sin(x) * (1.0 - cos(eps))); else tmp = cos(x) * (2.0 * sin((eps * 0.5))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.32e-5], N[Not[LessEqual[eps, 0.00185]], $MachinePrecision]], N[(N[Sin[eps], $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[(1.0 - N[Cos[eps], $MachinePrecision]), $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 -1.32 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 0.00185\right):\\
\;\;\;\;\sin \varepsilon - \sin x \cdot \left(1 - \cos \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if eps < -1.32000000000000007e-5 or 0.0018500000000000001 < eps Initial program 54.8%
sin-sum99.4%
associate--l+99.3%
Applied egg-rr99.3%
+-commutative99.3%
associate-+l-99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.4%
Simplified99.4%
Taylor expanded in x around 0 59.4%
if -1.32000000000000007e-5 < eps < 0.0018500000000000001Initial program 29.7%
diff-sin29.7%
div-inv29.7%
associate--l+29.7%
metadata-eval29.7%
div-inv29.7%
+-commutative29.7%
associate-+l+29.7%
metadata-eval29.7%
Applied egg-rr29.7%
associate-*r*29.7%
*-commutative29.7%
*-commutative29.7%
+-commutative29.7%
count-229.7%
fma-def29.7%
sub-neg29.7%
mul-1-neg29.7%
+-commutative29.7%
associate-+r+98.9%
mul-1-neg98.9%
sub-neg98.9%
+-inverses98.9%
remove-double-neg98.9%
mul-1-neg98.9%
sub-neg98.9%
neg-sub098.9%
mul-1-neg98.9%
remove-double-neg98.9%
Simplified98.9%
Taylor expanded in eps around 0 98.6%
Final simplification76.6%
(FPCore (x eps) :precision binary64 (if (<= eps -8500000000.0) (- (sin eps) (* (sin x) (- 1.0 (cos eps)))) (+ (* (sin eps) (cos x)) (* x (+ (cos eps) -1.0)))))
double code(double x, double eps) {
double tmp;
if (eps <= -8500000000.0) {
tmp = sin(eps) - (sin(x) * (1.0 - cos(eps)));
} else {
tmp = (sin(eps) * cos(x)) + (x * (cos(eps) + -1.0));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-8500000000.0d0)) then
tmp = sin(eps) - (sin(x) * (1.0d0 - cos(eps)))
else
tmp = (sin(eps) * cos(x)) + (x * (cos(eps) + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -8500000000.0) {
tmp = Math.sin(eps) - (Math.sin(x) * (1.0 - Math.cos(eps)));
} else {
tmp = (Math.sin(eps) * Math.cos(x)) + (x * (Math.cos(eps) + -1.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -8500000000.0: tmp = math.sin(eps) - (math.sin(x) * (1.0 - math.cos(eps))) else: tmp = (math.sin(eps) * math.cos(x)) + (x * (math.cos(eps) + -1.0)) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -8500000000.0) tmp = Float64(sin(eps) - Float64(sin(x) * Float64(1.0 - cos(eps)))); else tmp = Float64(Float64(sin(eps) * cos(x)) + Float64(x * Float64(cos(eps) + -1.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -8500000000.0) tmp = sin(eps) - (sin(x) * (1.0 - cos(eps))); else tmp = (sin(eps) * cos(x)) + (x * (cos(eps) + -1.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -8500000000.0], N[(N[Sin[eps], $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[(1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -8500000000:\\
\;\;\;\;\sin \varepsilon - \sin x \cdot \left(1 - \cos \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \varepsilon \cdot \cos x + x \cdot \left(\cos \varepsilon + -1\right)\\
\end{array}
\end{array}
if eps < -8.5e9Initial program 46.7%
sin-sum99.5%
associate--l+99.4%
Applied egg-rr99.4%
+-commutative99.4%
associate-+l-99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.5%
Simplified99.5%
Taylor expanded in x around 0 52.2%
if -8.5e9 < eps Initial program 42.6%
sin-sum57.4%
associate--l+57.4%
Applied egg-rr57.4%
+-commutative57.4%
associate-+l-99.4%
*-commutative99.4%
*-rgt-identity99.4%
distribute-lft-out--99.4%
Simplified99.4%
Taylor expanded in x around 0 84.6%
Final simplification75.2%
(FPCore (x eps) :precision binary64 (* (cos (* 0.5 (fma 2.0 x eps))) (* 2.0 (sin (* eps 0.5)))))
double code(double x, double eps) {
return cos((0.5 * fma(2.0, x, eps))) * (2.0 * sin((eps * 0.5)));
}
function code(x, eps) return Float64(cos(Float64(0.5 * fma(2.0, x, eps))) * Float64(2.0 * sin(Float64(eps * 0.5)))) end
code[x_, eps_] := N[(N[Cos[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right) \cdot \left(2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 43.8%
diff-sin43.2%
div-inv43.2%
associate--l+43.2%
metadata-eval43.2%
div-inv43.2%
+-commutative43.2%
associate-+l+43.2%
metadata-eval43.2%
Applied egg-rr43.2%
associate-*r*43.2%
*-commutative43.2%
*-commutative43.2%
+-commutative43.2%
count-243.2%
fma-def43.2%
sub-neg43.2%
mul-1-neg43.2%
+-commutative43.2%
associate-+r+74.6%
mul-1-neg74.6%
sub-neg74.6%
+-inverses74.6%
remove-double-neg74.6%
mul-1-neg74.6%
sub-neg74.6%
neg-sub074.6%
mul-1-neg74.6%
remove-double-neg74.6%
Simplified74.6%
Final simplification74.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.00015) (not (<= eps 0.00185))) (sin eps) (* eps (cos x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00015) || !(eps <= 0.00185)) {
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 <= (-0.00015d0)) .or. (.not. (eps <= 0.00185d0))) 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 <= -0.00015) || !(eps <= 0.00185)) {
tmp = Math.sin(eps);
} else {
tmp = eps * Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00015) or not (eps <= 0.00185): tmp = math.sin(eps) else: tmp = eps * math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00015) || !(eps <= 0.00185)) tmp = sin(eps); else tmp = Float64(eps * cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00015) || ~((eps <= 0.00185))) tmp = sin(eps); else tmp = eps * cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00015], N[Not[LessEqual[eps, 0.00185]], $MachinePrecision]], N[Sin[eps], $MachinePrecision], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00015 \lor \neg \left(\varepsilon \leq 0.00185\right):\\
\;\;\;\;\sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\end{array}
\end{array}
if eps < -1.49999999999999987e-4 or 0.0018500000000000001 < eps Initial program 54.8%
Taylor expanded in x around 0 56.1%
if -1.49999999999999987e-4 < eps < 0.0018500000000000001Initial program 29.7%
Taylor expanded in eps around 0 98.6%
Final simplification74.7%
(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 43.8%
Taylor expanded in x around 0 56.9%
Final simplification56.9%
(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 43.8%
Taylor expanded in eps around 0 44.9%
Taylor expanded in x around 0 27.1%
Final simplification27.1%
(FPCore (x eps) :precision binary64 (fma (sin x) (- (cos eps) 1.0) (* (sin eps) (cos x))))
double code(double x, double eps) {
return fma(sin(x), (cos(eps) - 1.0), (sin(eps) * cos(x)));
}
function code(x, eps) return fma(sin(x), Float64(cos(eps) - 1.0), Float64(sin(eps) * cos(x))) end
code[x_, eps_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] - 1.0), $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin x, \cos \varepsilon - 1, \sin \varepsilon \cdot \cos x\right)
\end{array}
herbie shell --seed 2023309
(FPCore (x eps)
:name "2sin (example 3.3)"
:precision binary64
:herbie-target
(fma (sin x) (- (cos eps) 1.0) (* (sin eps) (cos x)))
(- (sin (+ x eps)) (sin x)))