
(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 9 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 (let* ((t_0 (sin (* eps 0.5)))) (* (fma (cos (* eps 0.5)) (cos x) (* (- (sin x)) t_0)) (* t_0 2.0))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
return fma(cos((eps * 0.5)), cos(x), (-sin(x) * t_0)) * (t_0 * 2.0);
}
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) return Float64(fma(cos(Float64(eps * 0.5)), cos(x), Float64(Float64(-sin(x)) * t_0)) * Float64(t_0 * 2.0)) end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[((-N[Sin[x], $MachinePrecision]) * t$95$0), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathsf{fma}\left(\cos \left(\varepsilon \cdot 0.5\right), \cos x, \left(-\sin x\right) \cdot t_0\right) \cdot \left(t_0 \cdot 2\right)
\end{array}
\end{array}
Initial program 41.5%
diff-sin41.0%
div-inv41.0%
metadata-eval41.0%
div-inv41.0%
+-commutative41.0%
metadata-eval41.0%
Applied egg-rr41.0%
associate-*r*41.0%
*-commutative41.0%
associate-*l*41.0%
+-commutative41.0%
associate--l+75.2%
+-inverses75.2%
*-commutative75.2%
associate-+r+75.2%
+-commutative75.2%
Simplified75.2%
distribute-lft-in75.2%
*-commutative75.2%
+-rgt-identity75.2%
cos-sum99.5%
+-rgt-identity99.5%
*-commutative99.5%
+-rgt-identity99.5%
*-commutative99.5%
Applied egg-rr99.5%
cancel-sign-sub-inv99.5%
*-commutative99.5%
count-299.5%
*-commutative99.5%
count-299.5%
count-299.5%
*-commutative99.5%
count-299.5%
distribute-lft-neg-in99.5%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.5%
associate-*r*99.5%
mul-1-neg99.5%
distribute-rgt-neg-in99.5%
*-commutative99.5%
fma-def99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
cancel-sign-sub-inv99.5%
*-commutative99.5%
fma-def99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (sin (+ eps x)) (sin x))))
(if (or (<= t_0 -2e-7) (not (<= t_0 1e-10)))
t_0
(* (cos x) (* (sin (* eps 0.5)) 2.0)))))
double code(double x, double eps) {
double t_0 = sin((eps + x)) - sin(x);
double tmp;
if ((t_0 <= -2e-7) || !(t_0 <= 1e-10)) {
tmp = t_0;
} else {
tmp = cos(x) * (sin((eps * 0.5)) * 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((eps + x)) - sin(x)
if ((t_0 <= (-2d-7)) .or. (.not. (t_0 <= 1d-10))) then
tmp = t_0
else
tmp = cos(x) * (sin((eps * 0.5d0)) * 2.0d0)
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 <= -2e-7) || !(t_0 <= 1e-10)) {
tmp = t_0;
} else {
tmp = Math.cos(x) * (Math.sin((eps * 0.5)) * 2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps + x)) - math.sin(x) tmp = 0 if (t_0 <= -2e-7) or not (t_0 <= 1e-10): tmp = t_0 else: tmp = math.cos(x) * (math.sin((eps * 0.5)) * 2.0) return tmp
function code(x, eps) t_0 = Float64(sin(Float64(eps + x)) - sin(x)) tmp = 0.0 if ((t_0 <= -2e-7) || !(t_0 <= 1e-10)) tmp = t_0; else tmp = Float64(cos(x) * Float64(sin(Float64(eps * 0.5)) * 2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps + x)) - sin(x); tmp = 0.0; if ((t_0 <= -2e-7) || ~((t_0 <= 1e-10))) tmp = t_0; else tmp = cos(x) * (sin((eps * 0.5)) * 2.0); 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, -2e-7], N[Not[LessEqual[t$95$0, 1e-10]], $MachinePrecision]], t$95$0, N[(N[Cos[x], $MachinePrecision] * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon + x\right) - \sin x\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{-7} \lor \neg \left(t_0 \leq 10^{-10}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot 2\right)\\
\end{array}
\end{array}
if (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < -1.9999999999999999e-7 or 1.00000000000000004e-10 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) Initial program 68.0%
if -1.9999999999999999e-7 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < 1.00000000000000004e-10Initial program 24.6%
diff-sin24.6%
div-inv24.6%
metadata-eval24.6%
div-inv24.6%
+-commutative24.6%
metadata-eval24.6%
Applied egg-rr24.6%
associate-*r*24.6%
*-commutative24.6%
associate-*l*24.6%
+-commutative24.6%
associate--l+80.6%
+-inverses80.6%
*-commutative80.6%
associate-+r+80.6%
+-commutative80.6%
Simplified80.6%
distribute-lft-in80.6%
*-commutative80.6%
+-rgt-identity80.6%
cos-sum99.6%
+-rgt-identity99.6%
*-commutative99.6%
+-rgt-identity99.6%
*-commutative99.6%
Applied egg-rr99.6%
cancel-sign-sub-inv99.6%
*-commutative99.6%
count-299.6%
*-commutative99.6%
count-299.6%
count-299.6%
*-commutative99.6%
count-299.6%
distribute-lft-neg-in99.6%
fma-def99.6%
Simplified99.6%
Taylor expanded in eps around inf 99.6%
associate-*r*99.6%
mul-1-neg99.6%
distribute-rgt-neg-in99.6%
*-commutative99.6%
fma-def99.6%
*-commutative99.6%
*-commutative99.6%
Simplified99.6%
Taylor expanded in eps around 0 80.6%
Final simplification75.7%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- (sin (+ eps x)) (sin x)))) (if (or (<= t_0 -2e-7) (not (<= t_0 1e-10))) t_0 (* eps (cos x)))))
double code(double x, double eps) {
double t_0 = sin((eps + x)) - sin(x);
double tmp;
if ((t_0 <= -2e-7) || !(t_0 <= 1e-10)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = sin((eps + x)) - sin(x)
if ((t_0 <= (-2d-7)) .or. (.not. (t_0 <= 1d-10))) then
tmp = t_0
else
tmp = eps * cos(x)
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 <= -2e-7) || !(t_0 <= 1e-10)) {
tmp = t_0;
} else {
tmp = eps * Math.cos(x);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps + x)) - math.sin(x) tmp = 0 if (t_0 <= -2e-7) or not (t_0 <= 1e-10): tmp = t_0 else: tmp = eps * math.cos(x) return tmp
function code(x, eps) t_0 = Float64(sin(Float64(eps + x)) - sin(x)) tmp = 0.0 if ((t_0 <= -2e-7) || !(t_0 <= 1e-10)) tmp = t_0; else tmp = Float64(eps * cos(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps + x)) - sin(x); tmp = 0.0; if ((t_0 <= -2e-7) || ~((t_0 <= 1e-10))) tmp = t_0; else tmp = eps * cos(x); 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, -2e-7], N[Not[LessEqual[t$95$0, 1e-10]], $MachinePrecision]], t$95$0, N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon + x\right) - \sin x\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{-7} \lor \neg \left(t_0 \leq 10^{-10}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\end{array}
\end{array}
if (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < -1.9999999999999999e-7 or 1.00000000000000004e-10 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) Initial program 68.0%
if -1.9999999999999999e-7 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < 1.00000000000000004e-10Initial program 24.6%
Taylor expanded in eps around 0 78.9%
Final simplification74.6%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* eps 0.5)))) (* (* t_0 2.0) (- (* (cos (* eps 0.5)) (cos x)) (* (sin x) t_0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
return (t_0 * 2.0) * ((cos((eps * 0.5)) * cos(x)) - (sin(x) * t_0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = sin((eps * 0.5d0))
code = (t_0 * 2.0d0) * ((cos((eps * 0.5d0)) * cos(x)) - (sin(x) * t_0))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
return (t_0 * 2.0) * ((Math.cos((eps * 0.5)) * Math.cos(x)) - (Math.sin(x) * t_0));
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) return (t_0 * 2.0) * ((math.cos((eps * 0.5)) * math.cos(x)) - (math.sin(x) * t_0))
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) return Float64(Float64(t_0 * 2.0) * Float64(Float64(cos(Float64(eps * 0.5)) * cos(x)) - Float64(sin(x) * t_0))) end
function tmp = code(x, eps) t_0 = sin((eps * 0.5)); tmp = (t_0 * 2.0) * ((cos((eps * 0.5)) * cos(x)) - (sin(x) * t_0)); end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(t$95$0 * 2.0), $MachinePrecision] * N[(N[(N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\left(t_0 \cdot 2\right) \cdot \left(\cos \left(\varepsilon \cdot 0.5\right) \cdot \cos x - \sin x \cdot t_0\right)
\end{array}
\end{array}
Initial program 41.5%
diff-sin41.0%
div-inv41.0%
metadata-eval41.0%
div-inv41.0%
+-commutative41.0%
metadata-eval41.0%
Applied egg-rr41.0%
associate-*r*41.0%
*-commutative41.0%
associate-*l*41.0%
+-commutative41.0%
associate--l+75.2%
+-inverses75.2%
*-commutative75.2%
associate-+r+75.2%
+-commutative75.2%
Simplified75.2%
distribute-lft-in75.2%
*-commutative75.2%
+-rgt-identity75.2%
cos-sum99.5%
+-rgt-identity99.5%
*-commutative99.5%
+-rgt-identity99.5%
*-commutative99.5%
Applied egg-rr99.5%
cancel-sign-sub-inv99.5%
*-commutative99.5%
count-299.5%
*-commutative99.5%
count-299.5%
count-299.5%
*-commutative99.5%
count-299.5%
distribute-lft-neg-in99.5%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.5%
associate-*r*99.5%
mul-1-neg99.5%
distribute-rgt-neg-in99.5%
*-commutative99.5%
fma-def99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (fma (cos x) (sin eps) (* (sin x) (+ -1.0 (cos eps)))))
double code(double x, double eps) {
return fma(cos(x), sin(eps), (sin(x) * (-1.0 + cos(eps))));
}
function code(x, eps) return fma(cos(x), sin(eps), Float64(sin(x) * Float64(-1.0 + cos(eps)))) end
code[x_, eps_] := N[(N[Cos[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos x, \sin \varepsilon, \sin x \cdot \left(-1 + \cos \varepsilon\right)\right)
\end{array}
Initial program 41.5%
sin-sum67.2%
associate--l+67.1%
Applied egg-rr67.1%
Taylor expanded in x around inf 67.2%
associate--l+99.2%
fma-def99.2%
*-commutative99.2%
*-rgt-identity99.2%
distribute-lft-out--99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (* (* (sin (* eps 0.5)) 2.0) (cos (+ (* eps 0.5) x))))
double code(double x, double eps) {
return (sin((eps * 0.5)) * 2.0) * cos(((eps * 0.5) + x));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (sin((eps * 0.5d0)) * 2.0d0) * cos(((eps * 0.5d0) + x))
end function
public static double code(double x, double eps) {
return (Math.sin((eps * 0.5)) * 2.0) * Math.cos(((eps * 0.5) + x));
}
def code(x, eps): return (math.sin((eps * 0.5)) * 2.0) * math.cos(((eps * 0.5) + x))
function code(x, eps) return Float64(Float64(sin(Float64(eps * 0.5)) * 2.0) * cos(Float64(Float64(eps * 0.5) + x))) end
function tmp = code(x, eps) tmp = (sin((eps * 0.5)) * 2.0) * cos(((eps * 0.5) + x)); end
code[x_, eps_] := N[(N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * N[Cos[N[(N[(eps * 0.5), $MachinePrecision] + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\sin \left(\varepsilon \cdot 0.5\right) \cdot 2\right) \cdot \cos \left(\varepsilon \cdot 0.5 + x\right)
\end{array}
Initial program 41.5%
diff-sin41.0%
div-inv41.0%
metadata-eval41.0%
div-inv41.0%
+-commutative41.0%
metadata-eval41.0%
Applied egg-rr41.0%
associate-*r*41.0%
*-commutative41.0%
associate-*l*41.0%
+-commutative41.0%
associate--l+75.2%
+-inverses75.2%
*-commutative75.2%
associate-+r+75.2%
+-commutative75.2%
Simplified75.2%
distribute-lft-in75.2%
*-commutative75.2%
+-rgt-identity75.2%
cos-sum99.5%
+-rgt-identity99.5%
*-commutative99.5%
+-rgt-identity99.5%
*-commutative99.5%
Applied egg-rr99.5%
cancel-sign-sub-inv99.5%
*-commutative99.5%
count-299.5%
*-commutative99.5%
count-299.5%
count-299.5%
*-commutative99.5%
count-299.5%
distribute-lft-neg-in99.5%
fma-def99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.5%
associate-*r*99.5%
mul-1-neg99.5%
distribute-rgt-neg-in99.5%
*-commutative99.5%
fma-def99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
cos-sum75.2%
Applied egg-rr75.2%
Final simplification75.2%
(FPCore (x eps) :precision binary64 (if (<= eps -2.8e-5) (sin eps) (if (<= eps 0.66) (* eps (cos x)) (sin eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -2.8e-5) {
tmp = sin(eps);
} else if (eps <= 0.66) {
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 <= (-2.8d-5)) then
tmp = sin(eps)
else if (eps <= 0.66d0) 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 <= -2.8e-5) {
tmp = Math.sin(eps);
} else if (eps <= 0.66) {
tmp = eps * Math.cos(x);
} else {
tmp = Math.sin(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -2.8e-5: tmp = math.sin(eps) elif eps <= 0.66: tmp = eps * math.cos(x) else: tmp = math.sin(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -2.8e-5) tmp = sin(eps); elseif (eps <= 0.66) tmp = Float64(eps * cos(x)); else tmp = sin(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -2.8e-5) tmp = sin(eps); elseif (eps <= 0.66) tmp = eps * cos(x); else tmp = sin(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -2.8e-5], N[Sin[eps], $MachinePrecision], If[LessEqual[eps, 0.66], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision], N[Sin[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.8 \cdot 10^{-5}:\\
\;\;\;\;\sin \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 0.66:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin \varepsilon\\
\end{array}
\end{array}
if eps < -2.79999999999999996e-5 or 0.660000000000000031 < eps Initial program 51.9%
Taylor expanded in x around 0 51.7%
if -2.79999999999999996e-5 < eps < 0.660000000000000031Initial program 30.7%
Taylor expanded in eps around 0 98.1%
Final simplification74.4%
(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.5%
Taylor expanded in x around 0 52.6%
Final simplification52.6%
(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.5%
Taylor expanded in eps around 0 50.2%
fma-def50.2%
*-commutative50.2%
unpow250.2%
Simplified50.2%
Taylor expanded in x around 0 27.8%
Final simplification27.8%
(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 2023274
(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)))