
(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
(if (<= eps -0.00016)
(fma (cos eps) (sin x) (fma (sin eps) (cos x) (- (sin x))))
(if (<= eps 0.00018)
(+
(* -0.5 (* (sin x) (pow eps 2.0)))
(* (cos x) (+ eps (* -0.16666666666666666 (pow eps 3.0)))))
(- (fma (sin x) (cos eps) (* (sin eps) (cos x))) (sin x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.00016) {
tmp = fma(cos(eps), sin(x), fma(sin(eps), cos(x), -sin(x)));
} else if (eps <= 0.00018) {
tmp = (-0.5 * (sin(x) * pow(eps, 2.0))) + (cos(x) * (eps + (-0.16666666666666666 * pow(eps, 3.0))));
} else {
tmp = fma(sin(x), cos(eps), (sin(eps) * cos(x))) - sin(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.00016) tmp = fma(cos(eps), sin(x), fma(sin(eps), cos(x), Float64(-sin(x)))); elseif (eps <= 0.00018) tmp = Float64(Float64(-0.5 * Float64(sin(x) * (eps ^ 2.0))) + Float64(cos(x) * Float64(eps + Float64(-0.16666666666666666 * (eps ^ 3.0))))); 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, -0.00016], 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, 0.00018], N[(N[(-0.5 * N[(N[Sin[x], $MachinePrecision] * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(eps + N[(-0.16666666666666666 * N[Power[eps, 3.0], $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 -0.00016:\\
\;\;\;\;\mathsf{fma}\left(\cos \varepsilon, \sin x, \mathsf{fma}\left(\sin \varepsilon, \cos x, -\sin x\right)\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00018:\\
\;\;\;\;-0.5 \cdot \left(\sin x \cdot {\varepsilon}^{2}\right) + \cos x \cdot \left(\varepsilon + -0.16666666666666666 \cdot {\varepsilon}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin x, \cos \varepsilon, \sin \varepsilon \cdot \cos x\right) - \sin x\\
\end{array}
\end{array}
if eps < -1.60000000000000013e-4Initial program 53.1%
sin-sum99.1%
associate--l+99.0%
Applied egg-rr99.0%
*-commutative99.0%
fma-udef99.1%
*-commutative99.1%
fma-neg99.2%
Simplified99.2%
if -1.60000000000000013e-4 < eps < 1.80000000000000011e-4Initial program 25.3%
Taylor expanded in eps around 0 99.9%
fma-def99.9%
+-commutative99.9%
associate-*r*99.9%
distribute-rgt-out99.9%
Simplified99.9%
Taylor expanded in x around inf 99.9%
if 1.80000000000000011e-4 < eps Initial program 52.3%
sin-sum99.6%
fma-def99.6%
Applied egg-rr99.6%
Final simplification99.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (sin (+ eps x)) (sin x))))
(if (or (<= t_0 -0.02) (not (<= t_0 1e-51)))
t_0
(* (cos x) (* 2.0 (sin (* eps 0.5)))))))
double code(double x, double eps) {
double t_0 = sin((eps + x)) - sin(x);
double tmp;
if ((t_0 <= -0.02) || !(t_0 <= 1e-51)) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = sin((eps + x)) - sin(x)
if ((t_0 <= (-0.02d0)) .or. (.not. (t_0 <= 1d-51))) then
tmp = t_0
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 t_0 = Math.sin((eps + x)) - Math.sin(x);
double tmp;
if ((t_0 <= -0.02) || !(t_0 <= 1e-51)) {
tmp = t_0;
} else {
tmp = Math.cos(x) * (2.0 * Math.sin((eps * 0.5)));
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps + x)) - math.sin(x) tmp = 0 if (t_0 <= -0.02) or not (t_0 <= 1e-51): tmp = t_0 else: tmp = math.cos(x) * (2.0 * math.sin((eps * 0.5))) return tmp
function code(x, eps) t_0 = Float64(sin(Float64(eps + x)) - sin(x)) tmp = 0.0 if ((t_0 <= -0.02) || !(t_0 <= 1e-51)) tmp = t_0; else tmp = Float64(cos(x) * Float64(2.0 * sin(Float64(eps * 0.5)))); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps + x)) - sin(x); tmp = 0.0; if ((t_0 <= -0.02) || ~((t_0 <= 1e-51))) tmp = t_0; else tmp = cos(x) * (2.0 * sin((eps * 0.5))); 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[Or[LessEqual[t$95$0, -0.02], N[Not[LessEqual[t$95$0, 1e-51]], $MachinePrecision]], t$95$0, N[(N[Cos[x], $MachinePrecision] * N[(2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon + x\right) - \sin x\\
\mathbf{if}\;t_0 \leq -0.02 \lor \neg \left(t_0 \leq 10^{-51}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < -0.0200000000000000004 or 1e-51 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) Initial program 64.8%
if -0.0200000000000000004 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < 1e-51Initial program 21.0%
diff-sin21.0%
div-inv21.0%
associate--l+21.0%
metadata-eval21.0%
div-inv21.0%
+-commutative21.0%
associate-+l+21.0%
metadata-eval21.0%
Applied egg-rr21.0%
associate-*r*21.0%
*-commutative21.0%
*-commutative21.0%
+-commutative21.0%
count-221.0%
fma-def21.0%
associate-+r-21.0%
+-commutative21.0%
associate--l+86.5%
+-inverses86.5%
Simplified86.5%
Taylor expanded in x around inf 86.5%
associate-*r*86.5%
*-commutative86.5%
associate-*r*86.5%
*-commutative86.5%
Simplified86.5%
Taylor expanded in eps around 0 86.5%
Final simplification77.9%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00016) (not (<= eps 0.000165)))
(- (fma (sin x) (cos eps) (* (sin eps) (cos x))) (sin x))
(+
(* -0.5 (* (sin x) (pow eps 2.0)))
(* (cos x) (+ eps (* -0.16666666666666666 (pow eps 3.0)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00016) || !(eps <= 0.000165)) {
tmp = fma(sin(x), cos(eps), (sin(eps) * cos(x))) - sin(x);
} else {
tmp = (-0.5 * (sin(x) * pow(eps, 2.0))) + (cos(x) * (eps + (-0.16666666666666666 * pow(eps, 3.0))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -0.00016) || !(eps <= 0.000165)) tmp = Float64(fma(sin(x), cos(eps), Float64(sin(eps) * cos(x))) - sin(x)); else tmp = Float64(Float64(-0.5 * Float64(sin(x) * (eps ^ 2.0))) + Float64(cos(x) * Float64(eps + Float64(-0.16666666666666666 * (eps ^ 3.0))))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00016], N[Not[LessEqual[eps, 0.000165]], $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[(N[(-0.5 * N[(N[Sin[x], $MachinePrecision] * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(eps + N[(-0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00016 \lor \neg \left(\varepsilon \leq 0.000165\right):\\
\;\;\;\;\mathsf{fma}\left(\sin x, \cos \varepsilon, \sin \varepsilon \cdot \cos x\right) - \sin x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\sin x \cdot {\varepsilon}^{2}\right) + \cos x \cdot \left(\varepsilon + -0.16666666666666666 \cdot {\varepsilon}^{3}\right)\\
\end{array}
\end{array}
if eps < -1.60000000000000013e-4 or 1.65e-4 < eps Initial program 52.7%
sin-sum99.3%
fma-def99.4%
Applied egg-rr99.4%
if -1.60000000000000013e-4 < eps < 1.65e-4Initial program 25.3%
Taylor expanded in eps around 0 99.9%
fma-def99.9%
+-commutative99.9%
associate-*r*99.9%
distribute-rgt-out99.9%
Simplified99.9%
Taylor expanded in x around inf 99.9%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00017) (not (<= eps 0.00018)))
(+ (* (cos eps) (sin x)) (- (* (sin eps) (cos x)) (sin x)))
(+
(* -0.5 (* (sin x) (pow eps 2.0)))
(* (cos x) (+ eps (* -0.16666666666666666 (pow eps 3.0)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00017) || !(eps <= 0.00018)) {
tmp = (cos(eps) * sin(x)) + ((sin(eps) * cos(x)) - sin(x));
} else {
tmp = (-0.5 * (sin(x) * pow(eps, 2.0))) + (cos(x) * (eps + (-0.16666666666666666 * pow(eps, 3.0))));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.00017d0)) .or. (.not. (eps <= 0.00018d0))) then
tmp = (cos(eps) * sin(x)) + ((sin(eps) * cos(x)) - sin(x))
else
tmp = ((-0.5d0) * (sin(x) * (eps ** 2.0d0))) + (cos(x) * (eps + ((-0.16666666666666666d0) * (eps ** 3.0d0))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.00017) || !(eps <= 0.00018)) {
tmp = (Math.cos(eps) * Math.sin(x)) + ((Math.sin(eps) * Math.cos(x)) - Math.sin(x));
} else {
tmp = (-0.5 * (Math.sin(x) * Math.pow(eps, 2.0))) + (Math.cos(x) * (eps + (-0.16666666666666666 * Math.pow(eps, 3.0))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00017) or not (eps <= 0.00018): tmp = (math.cos(eps) * math.sin(x)) + ((math.sin(eps) * math.cos(x)) - math.sin(x)) else: tmp = (-0.5 * (math.sin(x) * math.pow(eps, 2.0))) + (math.cos(x) * (eps + (-0.16666666666666666 * math.pow(eps, 3.0)))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00017) || !(eps <= 0.00018)) tmp = Float64(Float64(cos(eps) * sin(x)) + Float64(Float64(sin(eps) * cos(x)) - sin(x))); else tmp = Float64(Float64(-0.5 * Float64(sin(x) * (eps ^ 2.0))) + Float64(cos(x) * Float64(eps + Float64(-0.16666666666666666 * (eps ^ 3.0))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00017) || ~((eps <= 0.00018))) tmp = (cos(eps) * sin(x)) + ((sin(eps) * cos(x)) - sin(x)); else tmp = (-0.5 * (sin(x) * (eps ^ 2.0))) + (cos(x) * (eps + (-0.16666666666666666 * (eps ^ 3.0)))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00017], N[Not[LessEqual[eps, 0.00018]], $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[(N[(-0.5 * N[(N[Sin[x], $MachinePrecision] * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(eps + N[(-0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00017 \lor \neg \left(\varepsilon \leq 0.00018\right):\\
\;\;\;\;\cos \varepsilon \cdot \sin x + \left(\sin \varepsilon \cdot \cos x - \sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\sin x \cdot {\varepsilon}^{2}\right) + \cos x \cdot \left(\varepsilon + -0.16666666666666666 \cdot {\varepsilon}^{3}\right)\\
\end{array}
\end{array}
if eps < -1.7e-4 or 1.80000000000000011e-4 < eps Initial program 52.7%
sin-sum99.3%
associate--l+99.3%
Applied egg-rr99.3%
if -1.7e-4 < eps < 1.80000000000000011e-4Initial program 25.3%
Taylor expanded in eps around 0 99.9%
fma-def99.9%
+-commutative99.9%
associate-*r*99.9%
distribute-rgt-out99.9%
Simplified99.9%
Taylor expanded in x around inf 99.9%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.00017) (not (<= eps 0.000195)))
(- (+ (* (sin eps) (cos x)) (* (cos eps) (sin x))) (sin x))
(+
(* -0.5 (* (sin x) (pow eps 2.0)))
(* (cos x) (+ eps (* -0.16666666666666666 (pow eps 3.0)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00017) || !(eps <= 0.000195)) {
tmp = ((sin(eps) * cos(x)) + (cos(eps) * sin(x))) - sin(x);
} else {
tmp = (-0.5 * (sin(x) * pow(eps, 2.0))) + (cos(x) * (eps + (-0.16666666666666666 * pow(eps, 3.0))));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.00017d0)) .or. (.not. (eps <= 0.000195d0))) then
tmp = ((sin(eps) * cos(x)) + (cos(eps) * sin(x))) - sin(x)
else
tmp = ((-0.5d0) * (sin(x) * (eps ** 2.0d0))) + (cos(x) * (eps + ((-0.16666666666666666d0) * (eps ** 3.0d0))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.00017) || !(eps <= 0.000195)) {
tmp = ((Math.sin(eps) * Math.cos(x)) + (Math.cos(eps) * Math.sin(x))) - Math.sin(x);
} else {
tmp = (-0.5 * (Math.sin(x) * Math.pow(eps, 2.0))) + (Math.cos(x) * (eps + (-0.16666666666666666 * Math.pow(eps, 3.0))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00017) or not (eps <= 0.000195): tmp = ((math.sin(eps) * math.cos(x)) + (math.cos(eps) * math.sin(x))) - math.sin(x) else: tmp = (-0.5 * (math.sin(x) * math.pow(eps, 2.0))) + (math.cos(x) * (eps + (-0.16666666666666666 * math.pow(eps, 3.0)))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00017) || !(eps <= 0.000195)) tmp = Float64(Float64(Float64(sin(eps) * cos(x)) + Float64(cos(eps) * sin(x))) - sin(x)); else tmp = Float64(Float64(-0.5 * Float64(sin(x) * (eps ^ 2.0))) + Float64(cos(x) * Float64(eps + Float64(-0.16666666666666666 * (eps ^ 3.0))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.00017) || ~((eps <= 0.000195))) tmp = ((sin(eps) * cos(x)) + (cos(eps) * sin(x))) - sin(x); else tmp = (-0.5 * (sin(x) * (eps ^ 2.0))) + (cos(x) * (eps + (-0.16666666666666666 * (eps ^ 3.0)))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00017], N[Not[LessEqual[eps, 0.000195]], $MachinePrecision]], N[(N[(N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(N[Sin[x], $MachinePrecision] * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(eps + N[(-0.16666666666666666 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00017 \lor \neg \left(\varepsilon \leq 0.000195\right):\\
\;\;\;\;\left(\sin \varepsilon \cdot \cos x + \cos \varepsilon \cdot \sin x\right) - \sin x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\sin x \cdot {\varepsilon}^{2}\right) + \cos x \cdot \left(\varepsilon + -0.16666666666666666 \cdot {\varepsilon}^{3}\right)\\
\end{array}
\end{array}
if eps < -1.7e-4 or 1.94999999999999996e-4 < eps Initial program 52.7%
sin-sum99.3%
Applied egg-rr99.3%
if -1.7e-4 < eps < 1.94999999999999996e-4Initial program 25.3%
Taylor expanded in eps around 0 99.9%
fma-def99.9%
+-commutative99.9%
associate-*r*99.9%
distribute-rgt-out99.9%
Simplified99.9%
Taylor expanded in x around inf 99.9%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (* 2.0 (* (cos (* 0.5 (- eps (* x -2.0)))) (sin (* eps 0.5)))))
double code(double x, double eps) {
return 2.0 * (cos((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 * (cos((0.5d0 * (eps - (x * (-2.0d0))))) * sin((eps * 0.5d0)))
end function
public static double code(double x, double eps) {
return 2.0 * (Math.cos((0.5 * (eps - (x * -2.0)))) * Math.sin((eps * 0.5)));
}
def code(x, eps): return 2.0 * (math.cos((0.5 * (eps - (x * -2.0)))) * math.sin((eps * 0.5)))
function code(x, eps) return Float64(2.0 * Float64(cos(Float64(0.5 * Float64(eps - Float64(x * -2.0)))) * sin(Float64(eps * 0.5)))) end
function tmp = code(x, eps) tmp = 2.0 * (cos((0.5 * (eps - (x * -2.0)))) * sin((eps * 0.5))); end
code[x_, eps_] := N[(2.0 * N[(N[Cos[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(\cos \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 38.5%
add-sqr-sqrt19.5%
sqrt-unprod20.0%
pow220.0%
Applied egg-rr20.0%
sqrt-pow138.5%
metadata-eval38.5%
pow138.5%
diff-sin38.2%
associate-*r*38.2%
div-inv38.2%
associate--l+38.1%
metadata-eval38.1%
div-inv38.1%
associate-+l+38.1%
+-commutative38.1%
metadata-eval38.1%
Applied egg-rr38.1%
Taylor expanded in x around -inf 77.9%
Final simplification77.9%
(FPCore (x eps) :precision binary64 (* (cos (* 0.5 (+ x (+ eps x)))) (* 2.0 (sin (* eps 0.5)))))
double code(double x, double eps) {
return cos((0.5 * (x + (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 = cos((0.5d0 * (x + (eps + x)))) * (2.0d0 * sin((eps * 0.5d0)))
end function
public static double code(double x, double eps) {
return Math.cos((0.5 * (x + (eps + x)))) * (2.0 * Math.sin((eps * 0.5)));
}
def code(x, eps): return math.cos((0.5 * (x + (eps + x)))) * (2.0 * math.sin((eps * 0.5)))
function code(x, eps) return Float64(cos(Float64(0.5 * Float64(x + Float64(eps + x)))) * Float64(2.0 * sin(Float64(eps * 0.5)))) end
function tmp = code(x, eps) tmp = cos((0.5 * (x + (eps + x)))) * (2.0 * sin((eps * 0.5))); end
code[x_, eps_] := N[(N[Cos[N[(0.5 * N[(x + N[(eps + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(0.5 \cdot \left(x + \left(\varepsilon + x\right)\right)\right) \cdot \left(2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 38.5%
add-sqr-sqrt19.5%
sqrt-unprod20.0%
pow220.0%
Applied egg-rr20.0%
sqrt-pow138.5%
metadata-eval38.5%
pow138.5%
diff-sin38.2%
associate-*r*38.2%
div-inv38.2%
associate--l+38.1%
metadata-eval38.1%
div-inv38.1%
associate-+l+38.1%
+-commutative38.1%
metadata-eval38.1%
Applied egg-rr38.1%
Taylor expanded in x around 0 77.9%
Final simplification77.9%
(FPCore (x eps) :precision binary64 (if (or (<= x -7.6e-6) (not (<= x 0.00024))) (* (cos x) (* 2.0 (sin (* eps 0.5)))) (+ (sin eps) (* x (+ (cos eps) -1.0)))))
double code(double x, double eps) {
double tmp;
if ((x <= -7.6e-6) || !(x <= 0.00024)) {
tmp = cos(x) * (2.0 * 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 <= (-7.6d-6)) .or. (.not. (x <= 0.00024d0))) then
tmp = cos(x) * (2.0d0 * 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 <= -7.6e-6) || !(x <= 0.00024)) {
tmp = Math.cos(x) * (2.0 * 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 <= -7.6e-6) or not (x <= 0.00024): tmp = math.cos(x) * (2.0 * 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 <= -7.6e-6) || !(x <= 0.00024)) tmp = Float64(cos(x) * Float64(2.0 * 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 <= -7.6e-6) || ~((x <= 0.00024))) tmp = cos(x) * (2.0 * 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, -7.6e-6], N[Not[LessEqual[x, 0.00024]], $MachinePrecision]], N[(N[Cos[x], $MachinePrecision] * N[(2.0 * 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 -7.6 \cdot 10^{-6} \lor \neg \left(x \leq 0.00024\right):\\
\;\;\;\;\cos x \cdot \left(2 \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 < -7.6000000000000001e-6 or 2.40000000000000006e-4 < x Initial program 7.1%
diff-sin6.7%
div-inv6.7%
associate--l+6.6%
metadata-eval6.6%
div-inv6.6%
+-commutative6.6%
associate-+l+6.5%
metadata-eval6.5%
Applied egg-rr6.5%
associate-*r*6.5%
*-commutative6.5%
*-commutative6.5%
+-commutative6.5%
count-26.5%
fma-def6.5%
associate-+r-6.6%
+-commutative6.6%
associate--l+56.1%
+-inverses56.1%
Simplified56.1%
Taylor expanded in x around inf 56.1%
associate-*r*56.1%
*-commutative56.1%
associate-*r*56.1%
*-commutative56.1%
Simplified56.1%
Taylor expanded in eps around 0 55.8%
if -7.6000000000000001e-6 < x < 2.40000000000000006e-4Initial program 69.4%
Taylor expanded in x around 0 99.9%
Final simplification78.0%
(FPCore (x eps) :precision binary64 (if (<= eps -0.0004) (- (sin (+ eps x)) (sin x)) (if (<= eps 5.8e-5) (* eps (cos x)) (sin eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0004) {
tmp = sin((eps + x)) - sin(x);
} else if (eps <= 5.8e-5) {
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 <= (-0.0004d0)) then
tmp = sin((eps + x)) - sin(x)
else if (eps <= 5.8d-5) 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 <= -0.0004) {
tmp = Math.sin((eps + x)) - Math.sin(x);
} else if (eps <= 5.8e-5) {
tmp = eps * Math.cos(x);
} else {
tmp = Math.sin(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.0004: tmp = math.sin((eps + x)) - math.sin(x) elif eps <= 5.8e-5: tmp = eps * math.cos(x) else: tmp = math.sin(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.0004) tmp = Float64(sin(Float64(eps + x)) - sin(x)); elseif (eps <= 5.8e-5) tmp = Float64(eps * cos(x)); else tmp = sin(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -0.0004) tmp = sin((eps + x)) - sin(x); elseif (eps <= 5.8e-5) tmp = eps * cos(x); else tmp = sin(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.0004], N[(N[Sin[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 5.8e-5], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision], N[Sin[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0004:\\
\;\;\;\;\sin \left(\varepsilon + x\right) - \sin x\\
\mathbf{elif}\;\varepsilon \leq 5.8 \cdot 10^{-5}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin \varepsilon\\
\end{array}
\end{array}
if eps < -4.00000000000000019e-4Initial program 53.1%
if -4.00000000000000019e-4 < eps < 5.8e-5Initial program 25.3%
Taylor expanded in eps around 0 99.6%
if 5.8e-5 < eps Initial program 52.3%
Taylor expanded in x around 0 53.1%
Final simplification77.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0021) (not (<= eps 3.8e-5))) (sin eps) (* eps (cos x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0021) || !(eps <= 3.8e-5)) {
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.0021d0)) .or. (.not. (eps <= 3.8d-5))) 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.0021) || !(eps <= 3.8e-5)) {
tmp = Math.sin(eps);
} else {
tmp = eps * Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0021) or not (eps <= 3.8e-5): tmp = math.sin(eps) else: tmp = eps * math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0021) || !(eps <= 3.8e-5)) 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.0021) || ~((eps <= 3.8e-5))) tmp = sin(eps); else tmp = eps * cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0021], N[Not[LessEqual[eps, 3.8e-5]], $MachinePrecision]], N[Sin[eps], $MachinePrecision], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0021 \lor \neg \left(\varepsilon \leq 3.8 \cdot 10^{-5}\right):\\
\;\;\;\;\sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\end{array}
\end{array}
if eps < -0.00209999999999999987 or 3.8000000000000002e-5 < eps Initial program 52.7%
Taylor expanded in x around 0 52.8%
if -0.00209999999999999987 < eps < 3.8000000000000002e-5Initial program 25.3%
Taylor expanded in eps around 0 99.6%
Final simplification77.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 38.5%
Taylor expanded in x around 0 55.3%
Final simplification55.3%
(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 38.5%
Taylor expanded in eps around 0 15.0%
Taylor expanded in x around 0 31.6%
Final simplification31.6%
(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 2023339
(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)))