
(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
(if (<= eps -3.95e-7)
(fma (cos eps) (sin x) (fma (sin eps) (cos x) (- (sin x))))
(if (<= eps 1.8e-8)
(* 2.0 (* (sin (* eps 0.5)) (+ (cos x) (* (sin x) (* eps -0.5)))))
(- (fma (sin x) (cos eps) (* (sin eps) (cos x))) (sin x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -3.95e-7) {
tmp = fma(cos(eps), sin(x), fma(sin(eps), cos(x), -sin(x)));
} else if (eps <= 1.8e-8) {
tmp = 2.0 * (sin((eps * 0.5)) * (cos(x) + (sin(x) * (eps * -0.5))));
} else {
tmp = fma(sin(x), cos(eps), (sin(eps) * cos(x))) - sin(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -3.95e-7) tmp = fma(cos(eps), sin(x), fma(sin(eps), cos(x), Float64(-sin(x)))); elseif (eps <= 1.8e-8) tmp = Float64(2.0 * Float64(sin(Float64(eps * 0.5)) * Float64(cos(x) + Float64(sin(x) * Float64(eps * -0.5))))); else tmp = Float64(fma(sin(x), cos(eps), Float64(sin(eps) * cos(x))) - sin(x)); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -3.95e-7], N[(N[Cos[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision] + (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 1.8e-8], N[(2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.95 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(\cos \varepsilon, \sin x, \mathsf{fma}\left(\sin \varepsilon, \cos x, -\sin x\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 1.8 \cdot 10^{-8}:\\
\;\;\;\;2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \left(\cos x + \sin x \cdot \left(\varepsilon \cdot -0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin x, \cos \varepsilon, \sin \varepsilon \cdot \cos x\right) - \sin x\\
\end{array}
\end{array}
if eps < -3.94999999999999977e-7Initial program 50.5%
sin-sum99.2%
associate--l+99.2%
Applied egg-rr99.2%
*-commutative99.2%
fma-udef99.3%
*-commutative99.3%
fma-neg99.4%
Simplified99.4%
if -3.94999999999999977e-7 < eps < 1.79999999999999991e-8Initial program 29.5%
diff-sin29.5%
div-inv29.5%
metadata-eval29.5%
div-inv29.5%
+-commutative29.5%
metadata-eval29.5%
Applied egg-rr29.5%
associate-*r*29.5%
*-commutative29.5%
associate-*l*29.5%
+-commutative29.5%
associate--l+99.6%
+-inverses99.6%
*-commutative99.6%
associate-+r+99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in eps around inf 99.6%
*-commutative99.6%
+-commutative99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
*-commutative99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
metadata-eval99.6%
cancel-sign-sub-inv99.6%
*-commutative99.6%
Simplified99.6%
Taylor expanded in eps around 0 99.8%
associate-*r*99.8%
Simplified99.8%
if 1.79999999999999991e-8 < eps Initial program 70.4%
sin-sum99.3%
fma-def99.4%
Applied egg-rr99.4%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (sin (+ eps x)) (sin x))))
(if (<= t_0 -0.01)
t_0
(if (<= t_0 0.0) (* 2.0 (* (cos x) (sin (* eps 0.5)))) (sin eps)))))
double code(double x, double eps) {
double t_0 = sin((eps + x)) - sin(x);
double tmp;
if (t_0 <= -0.01) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = 2.0 * (cos(x) * sin((eps * 0.5)));
} else {
tmp = sin(eps);
}
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 + x)) - sin(x)
if (t_0 <= (-0.01d0)) then
tmp = t_0
else if (t_0 <= 0.0d0) then
tmp = 2.0d0 * (cos(x) * sin((eps * 0.5d0)))
else
tmp = sin(eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps + x)) - Math.sin(x);
double tmp;
if (t_0 <= -0.01) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = 2.0 * (Math.cos(x) * Math.sin((eps * 0.5)));
} else {
tmp = Math.sin(eps);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps + x)) - math.sin(x) tmp = 0 if t_0 <= -0.01: tmp = t_0 elif t_0 <= 0.0: tmp = 2.0 * (math.cos(x) * math.sin((eps * 0.5))) else: tmp = math.sin(eps) return tmp
function code(x, eps) t_0 = Float64(sin(Float64(eps + x)) - sin(x)) tmp = 0.0 if (t_0 <= -0.01) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(2.0 * Float64(cos(x) * sin(Float64(eps * 0.5)))); else tmp = sin(eps); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps + x)) - sin(x); tmp = 0.0; if (t_0 <= -0.01) tmp = t_0; elseif (t_0 <= 0.0) tmp = 2.0 * (cos(x) * sin((eps * 0.5))); else tmp = sin(eps); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.01], t$95$0, If[LessEqual[t$95$0, 0.0], N[(2.0 * N[(N[Cos[x], $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[eps], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon + x\right) - \sin x\\
\mathbf{if}\;t_0 \leq -0.01:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;2 \cdot \left(\cos x \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \varepsilon\\
\end{array}
\end{array}
if (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < -0.0100000000000000002Initial program 69.2%
if -0.0100000000000000002 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < 0.0Initial program 16.7%
diff-sin16.7%
div-inv16.7%
metadata-eval16.7%
div-inv16.7%
+-commutative16.7%
metadata-eval16.7%
Applied egg-rr16.7%
associate-*r*16.7%
*-commutative16.7%
associate-*l*16.7%
+-commutative16.7%
associate--l+82.3%
+-inverses82.3%
*-commutative82.3%
associate-+r+82.3%
+-commutative82.3%
Simplified82.3%
Taylor expanded in eps around inf 82.3%
*-commutative82.3%
+-commutative82.3%
remove-double-neg82.3%
mul-1-neg82.3%
sub-neg82.3%
*-commutative82.3%
cancel-sign-sub-inv82.3%
metadata-eval82.3%
*-lft-identity82.3%
+-commutative82.3%
metadata-eval82.3%
cancel-sign-sub-inv82.3%
*-commutative82.3%
Simplified82.3%
Taylor expanded in eps around 0 82.3%
if 0.0 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) Initial program 85.3%
Taylor expanded in x around 0 85.5%
Final simplification80.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -9.8e-7) (not (<= eps 1.8e-8))) (- (fma (sin x) (cos eps) (* (sin eps) (cos x))) (sin x)) (* 2.0 (* (sin (* eps 0.5)) (+ (cos x) (* (sin x) (* eps -0.5)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -9.8e-7) || !(eps <= 1.8e-8)) {
tmp = fma(sin(x), cos(eps), (sin(eps) * cos(x))) - sin(x);
} else {
tmp = 2.0 * (sin((eps * 0.5)) * (cos(x) + (sin(x) * (eps * -0.5))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -9.8e-7) || !(eps <= 1.8e-8)) tmp = Float64(fma(sin(x), cos(eps), Float64(sin(eps) * cos(x))) - sin(x)); else tmp = Float64(2.0 * Float64(sin(Float64(eps * 0.5)) * Float64(cos(x) + Float64(sin(x) * Float64(eps * -0.5))))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -9.8e-7], N[Not[LessEqual[eps, 1.8e-8]], $MachinePrecision]], N[(N[(N[Sin[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -9.8 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 1.8 \cdot 10^{-8}\right):\\
\;\;\;\;\mathsf{fma}\left(\sin x, \cos \varepsilon, \sin \varepsilon \cdot \cos x\right) - \sin x\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \left(\cos x + \sin x \cdot \left(\varepsilon \cdot -0.5\right)\right)\right)\\
\end{array}
\end{array}
if eps < -9.7999999999999993e-7 or 1.79999999999999991e-8 < eps Initial program 60.1%
sin-sum99.3%
fma-def99.4%
Applied egg-rr99.4%
if -9.7999999999999993e-7 < eps < 1.79999999999999991e-8Initial program 29.5%
diff-sin29.5%
div-inv29.5%
metadata-eval29.5%
div-inv29.5%
+-commutative29.5%
metadata-eval29.5%
Applied egg-rr29.5%
associate-*r*29.5%
*-commutative29.5%
associate-*l*29.5%
+-commutative29.5%
associate--l+99.6%
+-inverses99.6%
*-commutative99.6%
associate-+r+99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in eps around inf 99.6%
*-commutative99.6%
+-commutative99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
*-commutative99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
metadata-eval99.6%
cancel-sign-sub-inv99.6%
*-commutative99.6%
Simplified99.6%
Taylor expanded in eps around 0 99.8%
associate-*r*99.8%
Simplified99.8%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.6e-7) (not (<= eps 1.8e-8))) (+ (* (cos eps) (sin x)) (- (* (sin eps) (cos x)) (sin x))) (* 2.0 (* (sin (* eps 0.5)) (+ (cos x) (* (sin x) (* eps -0.5)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.6e-7) || !(eps <= 1.8e-8)) {
tmp = (cos(eps) * sin(x)) + ((sin(eps) * cos(x)) - sin(x));
} else {
tmp = 2.0 * (sin((eps * 0.5)) * (cos(x) + (sin(x) * (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 <= (-4.6d-7)) .or. (.not. (eps <= 1.8d-8))) then
tmp = (cos(eps) * sin(x)) + ((sin(eps) * cos(x)) - sin(x))
else
tmp = 2.0d0 * (sin((eps * 0.5d0)) * (cos(x) + (sin(x) * (eps * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -4.6e-7) || !(eps <= 1.8e-8)) {
tmp = (Math.cos(eps) * Math.sin(x)) + ((Math.sin(eps) * Math.cos(x)) - Math.sin(x));
} else {
tmp = 2.0 * (Math.sin((eps * 0.5)) * (Math.cos(x) + (Math.sin(x) * (eps * -0.5))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4.6e-7) or not (eps <= 1.8e-8): tmp = (math.cos(eps) * math.sin(x)) + ((math.sin(eps) * math.cos(x)) - math.sin(x)) else: tmp = 2.0 * (math.sin((eps * 0.5)) * (math.cos(x) + (math.sin(x) * (eps * -0.5)))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -4.6e-7) || !(eps <= 1.8e-8)) tmp = Float64(Float64(cos(eps) * sin(x)) + Float64(Float64(sin(eps) * cos(x)) - sin(x))); else tmp = Float64(2.0 * Float64(sin(Float64(eps * 0.5)) * Float64(cos(x) + Float64(sin(x) * Float64(eps * -0.5))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -4.6e-7) || ~((eps <= 1.8e-8))) tmp = (cos(eps) * sin(x)) + ((sin(eps) * cos(x)) - sin(x)); else tmp = 2.0 * (sin((eps * 0.5)) * (cos(x) + (sin(x) * (eps * -0.5)))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.6e-7], N[Not[LessEqual[eps, 1.8e-8]], $MachinePrecision]], N[(N[(N[Cos[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.6 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 1.8 \cdot 10^{-8}\right):\\
\;\;\;\;\cos \varepsilon \cdot \sin x + \left(\sin \varepsilon \cdot \cos x - \sin x\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \left(\cos x + \sin x \cdot \left(\varepsilon \cdot -0.5\right)\right)\right)\\
\end{array}
\end{array}
if eps < -4.5999999999999999e-7 or 1.79999999999999991e-8 < eps Initial program 60.1%
sin-sum99.3%
associate--l+99.3%
Applied egg-rr99.3%
if -4.5999999999999999e-7 < eps < 1.79999999999999991e-8Initial program 29.5%
diff-sin29.5%
div-inv29.5%
metadata-eval29.5%
div-inv29.5%
+-commutative29.5%
metadata-eval29.5%
Applied egg-rr29.5%
associate-*r*29.5%
*-commutative29.5%
associate-*l*29.5%
+-commutative29.5%
associate--l+99.6%
+-inverses99.6%
*-commutative99.6%
associate-+r+99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in eps around inf 99.6%
*-commutative99.6%
+-commutative99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
*-commutative99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
metadata-eval99.6%
cancel-sign-sub-inv99.6%
*-commutative99.6%
Simplified99.6%
Taylor expanded in eps around 0 99.8%
associate-*r*99.8%
Simplified99.8%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (sin eps) (cos x))) (t_1 (* (cos eps) (sin x))))
(if (<= eps -8e-7)
(- (+ t_0 t_1) (sin x))
(if (<= eps 1.8e-8)
(* 2.0 (* (sin (* eps 0.5)) (+ (cos x) (* (sin x) (* eps -0.5)))))
(+ t_1 (- t_0 (sin x)))))))
double code(double x, double eps) {
double t_0 = sin(eps) * cos(x);
double t_1 = cos(eps) * sin(x);
double tmp;
if (eps <= -8e-7) {
tmp = (t_0 + t_1) - sin(x);
} else if (eps <= 1.8e-8) {
tmp = 2.0 * (sin((eps * 0.5)) * (cos(x) + (sin(x) * (eps * -0.5))));
} else {
tmp = t_1 + (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(eps) * cos(x)
t_1 = cos(eps) * sin(x)
if (eps <= (-8d-7)) then
tmp = (t_0 + t_1) - sin(x)
else if (eps <= 1.8d-8) then
tmp = 2.0d0 * (sin((eps * 0.5d0)) * (cos(x) + (sin(x) * (eps * (-0.5d0)))))
else
tmp = t_1 + (t_0 - sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin(eps) * Math.cos(x);
double t_1 = Math.cos(eps) * Math.sin(x);
double tmp;
if (eps <= -8e-7) {
tmp = (t_0 + t_1) - Math.sin(x);
} else if (eps <= 1.8e-8) {
tmp = 2.0 * (Math.sin((eps * 0.5)) * (Math.cos(x) + (Math.sin(x) * (eps * -0.5))));
} else {
tmp = t_1 + (t_0 - Math.sin(x));
}
return tmp;
}
def code(x, eps): t_0 = math.sin(eps) * math.cos(x) t_1 = math.cos(eps) * math.sin(x) tmp = 0 if eps <= -8e-7: tmp = (t_0 + t_1) - math.sin(x) elif eps <= 1.8e-8: tmp = 2.0 * (math.sin((eps * 0.5)) * (math.cos(x) + (math.sin(x) * (eps * -0.5)))) else: tmp = t_1 + (t_0 - math.sin(x)) return tmp
function code(x, eps) t_0 = Float64(sin(eps) * cos(x)) t_1 = Float64(cos(eps) * sin(x)) tmp = 0.0 if (eps <= -8e-7) tmp = Float64(Float64(t_0 + t_1) - sin(x)); elseif (eps <= 1.8e-8) tmp = Float64(2.0 * Float64(sin(Float64(eps * 0.5)) * Float64(cos(x) + Float64(sin(x) * Float64(eps * -0.5))))); else tmp = Float64(t_1 + Float64(t_0 - sin(x))); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin(eps) * cos(x); t_1 = cos(eps) * sin(x); tmp = 0.0; if (eps <= -8e-7) tmp = (t_0 + t_1) - sin(x); elseif (eps <= 1.8e-8) tmp = 2.0 * (sin((eps * 0.5)) * (cos(x) + (sin(x) * (eps * -0.5)))); else tmp = t_1 + (t_0 - sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -8e-7], N[(N[(t$95$0 + t$95$1), $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 1.8e-8], N[(2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(t$95$0 - N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \varepsilon \cdot \cos x\\
t_1 := \cos \varepsilon \cdot \sin x\\
\mathbf{if}\;\varepsilon \leq -8 \cdot 10^{-7}:\\
\;\;\;\;\left(t_0 + t_1\right) - \sin x\\
\mathbf{elif}\;\varepsilon \leq 1.8 \cdot 10^{-8}:\\
\;\;\;\;2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \left(\cos x + \sin x \cdot \left(\varepsilon \cdot -0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_1 + \left(t_0 - \sin x\right)\\
\end{array}
\end{array}
if eps < -7.9999999999999996e-7Initial program 50.5%
sin-sum99.2%
Applied egg-rr99.2%
if -7.9999999999999996e-7 < eps < 1.79999999999999991e-8Initial program 29.5%
diff-sin29.5%
div-inv29.5%
metadata-eval29.5%
div-inv29.5%
+-commutative29.5%
metadata-eval29.5%
Applied egg-rr29.5%
associate-*r*29.5%
*-commutative29.5%
associate-*l*29.5%
+-commutative29.5%
associate--l+99.6%
+-inverses99.6%
*-commutative99.6%
associate-+r+99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in eps around inf 99.6%
*-commutative99.6%
+-commutative99.6%
remove-double-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
*-commutative99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
metadata-eval99.6%
cancel-sign-sub-inv99.6%
*-commutative99.6%
Simplified99.6%
Taylor expanded in eps around 0 99.8%
associate-*r*99.8%
Simplified99.8%
if 1.79999999999999991e-8 < eps Initial program 70.4%
sin-sum99.3%
associate--l+99.4%
Applied egg-rr99.4%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (* 2.0 (* (sin (* eps 0.5)) (cos (* 0.5 (- eps (* x -2.0)))))))
double code(double x, double eps) {
return 2.0 * (sin((eps * 0.5)) * cos((0.5 * (eps - (x * -2.0)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 2.0d0 * (sin((eps * 0.5d0)) * cos((0.5d0 * (eps - (x * (-2.0d0))))))
end function
public static double code(double x, double eps) {
return 2.0 * (Math.sin((eps * 0.5)) * Math.cos((0.5 * (eps - (x * -2.0)))));
}
def code(x, eps): return 2.0 * (math.sin((eps * 0.5)) * math.cos((0.5 * (eps - (x * -2.0)))))
function code(x, eps) return Float64(2.0 * Float64(sin(Float64(eps * 0.5)) * cos(Float64(0.5 * Float64(eps - Float64(x * -2.0)))))) end
function tmp = code(x, eps) tmp = 2.0 * (sin((eps * 0.5)) * cos((0.5 * (eps - (x * -2.0))))); end
code[x_, eps_] := N[(2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * N[(eps - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right)\right)
\end{array}
Initial program 45.0%
diff-sin44.6%
div-inv44.6%
metadata-eval44.6%
div-inv44.6%
+-commutative44.6%
metadata-eval44.6%
Applied egg-rr44.6%
associate-*r*44.6%
*-commutative44.6%
associate-*l*44.6%
+-commutative44.6%
associate--l+79.8%
+-inverses79.8%
*-commutative79.8%
associate-+r+80.0%
+-commutative80.0%
Simplified80.0%
Taylor expanded in eps around inf 80.0%
*-commutative80.0%
+-commutative80.0%
remove-double-neg80.0%
mul-1-neg80.0%
sub-neg80.0%
*-commutative80.0%
cancel-sign-sub-inv80.0%
metadata-eval80.0%
*-lft-identity80.0%
+-commutative80.0%
metadata-eval80.0%
cancel-sign-sub-inv80.0%
*-commutative80.0%
Simplified80.0%
Final simplification80.0%
(FPCore (x eps) :precision binary64 (if (or (<= x -0.052) (not (<= x 0.00052))) (* 2.0 (* (cos x) (sin (* eps 0.5)))) (+ (sin eps) (* x (+ (cos eps) -1.0)))))
double code(double x, double eps) {
double tmp;
if ((x <= -0.052) || !(x <= 0.00052)) {
tmp = 2.0 * (cos(x) * sin((eps * 0.5)));
} else {
tmp = sin(eps) + (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 ((x <= (-0.052d0)) .or. (.not. (x <= 0.00052d0))) then
tmp = 2.0d0 * (cos(x) * sin((eps * 0.5d0)))
else
tmp = sin(eps) + (x * (cos(eps) + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -0.052) || !(x <= 0.00052)) {
tmp = 2.0 * (Math.cos(x) * Math.sin((eps * 0.5)));
} else {
tmp = Math.sin(eps) + (x * (Math.cos(eps) + -1.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -0.052) or not (x <= 0.00052): tmp = 2.0 * (math.cos(x) * math.sin((eps * 0.5))) else: tmp = math.sin(eps) + (x * (math.cos(eps) + -1.0)) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -0.052) || !(x <= 0.00052)) tmp = Float64(2.0 * Float64(cos(x) * sin(Float64(eps * 0.5)))); else tmp = Float64(sin(eps) + Float64(x * Float64(cos(eps) + -1.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -0.052) || ~((x <= 0.00052))) tmp = 2.0 * (cos(x) * sin((eps * 0.5))); else tmp = sin(eps) + (x * (cos(eps) + -1.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -0.052], N[Not[LessEqual[x, 0.00052]], $MachinePrecision]], N[(2.0 * N[(N[Cos[x], $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[eps], $MachinePrecision] + N[(x * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.052 \lor \neg \left(x \leq 0.00052\right):\\
\;\;\;\;2 \cdot \left(\cos x \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \varepsilon + x \cdot \left(\cos \varepsilon + -1\right)\\
\end{array}
\end{array}
if x < -0.0519999999999999976 or 5.19999999999999954e-4 < x Initial program 6.5%
diff-sin5.9%
div-inv5.9%
metadata-eval5.9%
div-inv5.9%
+-commutative5.9%
metadata-eval5.9%
Applied egg-rr5.9%
associate-*r*5.9%
*-commutative5.9%
associate-*l*5.9%
+-commutative5.9%
associate--l+59.2%
+-inverses59.2%
*-commutative59.2%
associate-+r+59.5%
+-commutative59.5%
Simplified59.5%
Taylor expanded in eps around inf 59.5%
*-commutative59.5%
+-commutative59.5%
remove-double-neg59.5%
mul-1-neg59.5%
sub-neg59.5%
*-commutative59.5%
cancel-sign-sub-inv59.5%
metadata-eval59.5%
*-lft-identity59.5%
+-commutative59.5%
metadata-eval59.5%
cancel-sign-sub-inv59.5%
*-commutative59.5%
Simplified59.5%
Taylor expanded in eps around 0 59.9%
if -0.0519999999999999976 < x < 5.19999999999999954e-4Initial program 79.6%
Taylor expanded in x around 0 98.9%
Final simplification80.5%
(FPCore (x eps) :precision binary64 (if (<= eps -1.9e-6) (sin eps) (if (<= eps 0.0106) (* eps (cos x)) (sin eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -1.9e-6) {
tmp = sin(eps);
} else if (eps <= 0.0106) {
tmp = eps * cos(x);
} else {
tmp = sin(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.9d-6)) then
tmp = sin(eps)
else if (eps <= 0.0106d0) then
tmp = eps * cos(x)
else
tmp = sin(eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -1.9e-6) {
tmp = Math.sin(eps);
} else if (eps <= 0.0106) {
tmp = eps * Math.cos(x);
} else {
tmp = Math.sin(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -1.9e-6: tmp = math.sin(eps) elif eps <= 0.0106: tmp = eps * math.cos(x) else: tmp = math.sin(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -1.9e-6) tmp = sin(eps); elseif (eps <= 0.0106) tmp = Float64(eps * cos(x)); else tmp = sin(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -1.9e-6) tmp = sin(eps); elseif (eps <= 0.0106) tmp = eps * cos(x); else tmp = sin(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -1.9e-6], N[Sin[eps], $MachinePrecision], If[LessEqual[eps, 0.0106], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision], N[Sin[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.9 \cdot 10^{-6}:\\
\;\;\;\;\sin \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 0.0106:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin \varepsilon\\
\end{array}
\end{array}
if eps < -1.9e-6 or 0.0106 < eps Initial program 60.2%
Taylor expanded in x around 0 61.2%
if -1.9e-6 < eps < 0.0106Initial program 29.8%
Taylor expanded in eps around 0 99.0%
Final simplification80.1%
(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 45.0%
Taylor expanded in x around 0 57.2%
Final simplification57.2%
(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 45.0%
diff-sin44.6%
div-inv44.6%
metadata-eval44.6%
div-inv44.6%
+-commutative44.6%
metadata-eval44.6%
Applied egg-rr44.6%
associate-*r*44.6%
*-commutative44.6%
associate-*l*44.6%
+-commutative44.6%
associate--l+79.8%
+-inverses79.8%
*-commutative79.8%
associate-+r+80.0%
+-commutative80.0%
Simplified80.0%
Taylor expanded in eps around 0 51.1%
*-commutative51.1%
Simplified51.1%
Taylor expanded in x around 0 28.1%
Final simplification28.1%
(FPCore (x eps) :precision binary64 (* 2.0 (* (cos (+ x (/ eps 2.0))) (sin (/ eps 2.0)))))
double code(double x, double eps) {
return 2.0 * (cos((x + (eps / 2.0))) * sin((eps / 2.0)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 2.0d0 * (cos((x + (eps / 2.0d0))) * sin((eps / 2.0d0)))
end function
public static double code(double x, double eps) {
return 2.0 * (Math.cos((x + (eps / 2.0))) * Math.sin((eps / 2.0)));
}
def code(x, eps): return 2.0 * (math.cos((x + (eps / 2.0))) * math.sin((eps / 2.0)))
function code(x, eps) return Float64(2.0 * Float64(cos(Float64(x + Float64(eps / 2.0))) * sin(Float64(eps / 2.0)))) end
function tmp = code(x, eps) tmp = 2.0 * (cos((x + (eps / 2.0))) * sin((eps / 2.0))); end
code[x_, eps_] := N[(2.0 * N[(N[Cos[N[(x + N[(eps / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(\cos \left(x + \frac{\varepsilon}{2}\right) \cdot \sin \left(\frac{\varepsilon}{2}\right)\right)
\end{array}
herbie shell --seed 2023297
(FPCore (x eps)
:name "2sin (example 3.3)"
:precision binary64
:herbie-target
(* 2.0 (* (cos (+ x (/ eps 2.0))) (sin (/ eps 2.0))))
(- (sin (+ x eps)) (sin x)))