
(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 11 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 eps) (cos x) (* (sin x) (/ (pow (sin eps) 2.0) (- -1.0 (cos eps))))))
double code(double x, double eps) {
return fma(sin(eps), cos(x), (sin(x) * (pow(sin(eps), 2.0) / (-1.0 - cos(eps)))));
}
function code(x, eps) return fma(sin(eps), cos(x), Float64(sin(x) * Float64((sin(eps) ^ 2.0) / Float64(-1.0 - cos(eps))))) end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision] / N[(-1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin \varepsilon, \cos x, \sin x \cdot \frac{{\sin \varepsilon}^{2}}{-1 - \cos \varepsilon}\right)
\end{array}
Initial program 44.2%
sin-sum69.1%
associate--l+69.1%
Applied egg-rr69.1%
associate-+r-69.1%
+-commutative69.1%
associate-+r-99.2%
*-commutative99.2%
sub-neg99.2%
fma-def99.3%
*-commutative99.3%
neg-mul-199.3%
distribute-rgt-out99.3%
Simplified99.3%
flip-+99.2%
frac-2neg99.2%
metadata-eval99.2%
sub-1-cos99.6%
pow299.6%
sub-neg99.6%
metadata-eval99.6%
Applied egg-rr99.6%
remove-double-neg99.6%
distribute-neg-in99.6%
metadata-eval99.6%
+-commutative99.6%
sub-neg99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (- (* (sin eps) (cos x)) (/ (pow (sin eps) 2.0) (/ (+ (cos eps) 1.0) (sin x)))))
double code(double x, double eps) {
return (sin(eps) * cos(x)) - (pow(sin(eps), 2.0) / ((cos(eps) + 1.0) / sin(x)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (sin(eps) * cos(x)) - ((sin(eps) ** 2.0d0) / ((cos(eps) + 1.0d0) / sin(x)))
end function
public static double code(double x, double eps) {
return (Math.sin(eps) * Math.cos(x)) - (Math.pow(Math.sin(eps), 2.0) / ((Math.cos(eps) + 1.0) / Math.sin(x)));
}
def code(x, eps): return (math.sin(eps) * math.cos(x)) - (math.pow(math.sin(eps), 2.0) / ((math.cos(eps) + 1.0) / math.sin(x)))
function code(x, eps) return Float64(Float64(sin(eps) * cos(x)) - Float64((sin(eps) ^ 2.0) / Float64(Float64(cos(eps) + 1.0) / sin(x)))) end
function tmp = code(x, eps) tmp = (sin(eps) * cos(x)) - ((sin(eps) ^ 2.0) / ((cos(eps) + 1.0) / sin(x))); end
code[x_, eps_] := N[(N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision] / N[(N[(N[Cos[eps], $MachinePrecision] + 1.0), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \varepsilon \cdot \cos x - \frac{{\sin \varepsilon}^{2}}{\frac{\cos \varepsilon + 1}{\sin x}}
\end{array}
Initial program 44.2%
sin-sum69.1%
associate--l+69.1%
Applied egg-rr69.1%
associate-+r-69.1%
+-commutative69.1%
associate-+r-99.2%
*-commutative99.2%
sub-neg99.2%
fma-def99.3%
*-commutative99.3%
neg-mul-199.3%
distribute-rgt-out99.3%
Simplified99.3%
fma-udef99.3%
*-commutative99.3%
distribute-lft-in99.2%
+-commutative99.2%
*-commutative99.2%
mul-1-neg99.2%
associate-+l+69.1%
sub-neg69.1%
associate-+l-99.2%
*-commutative99.2%
*-un-lft-identity99.2%
metadata-eval99.2%
*-commutative99.2%
distribute-rgt-out--99.3%
metadata-eval99.3%
Applied egg-rr99.3%
flip--99.2%
metadata-eval99.2%
metadata-eval99.2%
associate-*r/99.2%
metadata-eval99.2%
1-sub-cos99.6%
pow299.6%
+-commutative99.6%
Applied egg-rr99.6%
*-commutative99.6%
associate-/l*99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (fma (sin eps) (cos x) (* (sin x) (+ -1.0 (cos eps)))))
double code(double x, double eps) {
return fma(sin(eps), cos(x), (sin(x) * (-1.0 + cos(eps))));
}
function code(x, eps) return fma(sin(eps), cos(x), Float64(sin(x) * Float64(-1.0 + cos(eps)))) end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin \varepsilon, \cos x, \sin x \cdot \left(-1 + \cos \varepsilon\right)\right)
\end{array}
Initial program 44.2%
sin-sum69.1%
associate--l+69.1%
Applied egg-rr69.1%
associate-+r-69.1%
+-commutative69.1%
associate-+r-99.2%
*-commutative99.2%
sub-neg99.2%
fma-def99.3%
*-commutative99.3%
neg-mul-199.3%
distribute-rgt-out99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (fma (sin x) (+ -1.0 (cos eps)) (* (sin eps) (cos x))))
double code(double x, double eps) {
return fma(sin(x), (-1.0 + cos(eps)), (sin(eps) * cos(x)));
}
function code(x, eps) return fma(sin(x), Float64(-1.0 + cos(eps)), Float64(sin(eps) * cos(x))) end
code[x_, eps_] := N[(N[Sin[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin x, -1 + \cos \varepsilon, \sin \varepsilon \cdot \cos x\right)
\end{array}
Initial program 44.2%
sin-sum69.1%
associate--l+69.1%
Applied egg-rr69.1%
associate-+r-69.1%
+-commutative69.1%
associate-+r-99.2%
*-commutative99.2%
sub-neg99.2%
fma-def99.3%
*-commutative99.3%
neg-mul-199.3%
distribute-rgt-out99.3%
Simplified99.3%
fma-udef99.3%
*-commutative99.3%
distribute-lft-in99.2%
+-commutative99.2%
*-commutative99.2%
mul-1-neg99.2%
associate-+l+69.1%
sub-neg69.1%
associate-+l-99.2%
*-commutative99.2%
*-un-lft-identity99.2%
metadata-eval99.2%
*-commutative99.2%
distribute-rgt-out--99.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in eps around inf 99.3%
cancel-sign-sub-inv99.3%
sub-neg99.3%
distribute-lft-in99.2%
*-commutative99.2%
*-rgt-identity99.2%
associate-+l+69.1%
distribute-rgt-neg-out69.1%
distribute-lft-neg-out69.1%
remove-double-neg69.1%
associate-+r+99.2%
neg-mul-199.2%
distribute-rgt-in99.3%
+-commutative99.3%
Simplified99.3%
Final simplification99.3%
(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 44.2%
sin-sum69.1%
associate--l+69.1%
Applied egg-rr69.1%
associate-+r-69.1%
+-commutative69.1%
associate-+r-99.2%
*-commutative99.2%
sub-neg99.2%
fma-def99.3%
*-commutative99.3%
neg-mul-199.3%
distribute-rgt-out99.3%
Simplified99.3%
fma-udef99.3%
*-commutative99.3%
distribute-lft-in99.2%
+-commutative99.2%
*-commutative99.2%
mul-1-neg99.2%
associate-+l+69.1%
sub-neg69.1%
associate-+l-99.2%
*-commutative99.2%
*-un-lft-identity99.2%
metadata-eval99.2%
*-commutative99.2%
distribute-rgt-out--99.3%
metadata-eval99.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (<= eps -3.5e-6)
(sin eps)
(if (<= eps 6e-5)
(* eps (cos x))
(- (sin (+ eps x)) (+ 1.0 (+ (sin x) -1.0))))))
double code(double x, double eps) {
double tmp;
if (eps <= -3.5e-6) {
tmp = sin(eps);
} else if (eps <= 6e-5) {
tmp = eps * cos(x);
} else {
tmp = sin((eps + x)) - (1.0 + (sin(x) + -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 <= (-3.5d-6)) then
tmp = sin(eps)
else if (eps <= 6d-5) then
tmp = eps * cos(x)
else
tmp = sin((eps + x)) - (1.0d0 + (sin(x) + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -3.5e-6) {
tmp = Math.sin(eps);
} else if (eps <= 6e-5) {
tmp = eps * Math.cos(x);
} else {
tmp = Math.sin((eps + x)) - (1.0 + (Math.sin(x) + -1.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -3.5e-6: tmp = math.sin(eps) elif eps <= 6e-5: tmp = eps * math.cos(x) else: tmp = math.sin((eps + x)) - (1.0 + (math.sin(x) + -1.0)) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -3.5e-6) tmp = sin(eps); elseif (eps <= 6e-5) tmp = Float64(eps * cos(x)); else tmp = Float64(sin(Float64(eps + x)) - Float64(1.0 + Float64(sin(x) + -1.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -3.5e-6) tmp = sin(eps); elseif (eps <= 6e-5) tmp = eps * cos(x); else tmp = sin((eps + x)) - (1.0 + (sin(x) + -1.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -3.5e-6], N[Sin[eps], $MachinePrecision], If[LessEqual[eps, 6e-5], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[Sin[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[(1.0 + N[(N[Sin[x], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.5 \cdot 10^{-6}:\\
\;\;\;\;\sin \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 6 \cdot 10^{-5}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\varepsilon + x\right) - \left(1 + \left(\sin x + -1\right)\right)\\
\end{array}
\end{array}
if eps < -3.49999999999999995e-6Initial program 49.2%
Taylor expanded in x around 0 50.6%
if -3.49999999999999995e-6 < eps < 6.00000000000000015e-5Initial program 36.0%
Taylor expanded in eps around 0 99.0%
if 6.00000000000000015e-5 < eps Initial program 54.7%
expm1-log1p-u54.6%
expm1-udef54.7%
associate--r-54.4%
Applied egg-rr54.4%
associate-+l-54.7%
+-commutative54.7%
expm1-def54.6%
Simplified54.6%
expm1-udef54.7%
metadata-eval54.7%
sub-neg54.7%
log1p-udef54.7%
metadata-eval54.7%
add-exp-log54.7%
metadata-eval54.7%
metadata-eval54.7%
associate-+l+55.0%
metadata-eval55.0%
Applied egg-rr55.0%
Final simplification75.2%
(FPCore (x eps) :precision binary64 (* (sin (* eps 0.5)) (* 2.0 (cos (* 0.5 (+ eps (* x 2.0)))))))
double code(double x, double eps) {
return sin((eps * 0.5)) * (2.0 * cos((0.5 * (eps + (x * 2.0)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin((eps * 0.5d0)) * (2.0d0 * cos((0.5d0 * (eps + (x * 2.0d0)))))
end function
public static double code(double x, double eps) {
return Math.sin((eps * 0.5)) * (2.0 * Math.cos((0.5 * (eps + (x * 2.0)))));
}
def code(x, eps): return math.sin((eps * 0.5)) * (2.0 * math.cos((0.5 * (eps + (x * 2.0)))))
function code(x, eps) return Float64(sin(Float64(eps * 0.5)) * Float64(2.0 * cos(Float64(0.5 * Float64(eps + Float64(x * 2.0)))))) end
function tmp = code(x, eps) tmp = sin((eps * 0.5)) * (2.0 * cos((0.5 * (eps + (x * 2.0))))); end
code[x_, eps_] := N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[(2.0 * N[Cos[N[(0.5 * N[(eps + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(\varepsilon \cdot 0.5\right) \cdot \left(2 \cdot \cos \left(0.5 \cdot \left(\varepsilon + x \cdot 2\right)\right)\right)
\end{array}
Initial program 44.2%
diff-sin43.7%
div-inv43.7%
+-commutative43.7%
associate--l+75.1%
*-un-lft-identity75.1%
*-un-lft-identity75.1%
distribute-rgt-out--75.1%
metadata-eval75.1%
metadata-eval75.1%
div-inv75.1%
+-commutative75.1%
associate-+l+75.2%
count-275.2%
*-commutative75.2%
metadata-eval75.2%
Applied egg-rr75.2%
*-commutative75.2%
associate-*l*75.2%
mul0-rgt75.2%
*-commutative75.2%
Simplified75.2%
Final simplification75.2%
(FPCore (x eps) :precision binary64 (if (<= eps -7.2e-5) (sin eps) (if (<= eps 1.05e-5) (* eps (cos x)) (- (sin (+ eps x)) (sin x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -7.2e-5) {
tmp = sin(eps);
} else if (eps <= 1.05e-5) {
tmp = eps * cos(x);
} else {
tmp = sin((eps + x)) - sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-7.2d-5)) then
tmp = sin(eps)
else if (eps <= 1.05d-5) then
tmp = eps * cos(x)
else
tmp = sin((eps + x)) - sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -7.2e-5) {
tmp = Math.sin(eps);
} else if (eps <= 1.05e-5) {
tmp = eps * Math.cos(x);
} else {
tmp = Math.sin((eps + x)) - Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -7.2e-5: tmp = math.sin(eps) elif eps <= 1.05e-5: tmp = eps * math.cos(x) else: tmp = math.sin((eps + x)) - math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -7.2e-5) tmp = sin(eps); elseif (eps <= 1.05e-5) tmp = Float64(eps * cos(x)); else tmp = Float64(sin(Float64(eps + x)) - sin(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -7.2e-5) tmp = sin(eps); elseif (eps <= 1.05e-5) tmp = eps * cos(x); else tmp = sin((eps + x)) - sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -7.2e-5], N[Sin[eps], $MachinePrecision], If[LessEqual[eps, 1.05e-5], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[Sin[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -7.2 \cdot 10^{-5}:\\
\;\;\;\;\sin \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 1.05 \cdot 10^{-5}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\varepsilon + x\right) - \sin x\\
\end{array}
\end{array}
if eps < -7.20000000000000018e-5Initial program 49.2%
Taylor expanded in x around 0 50.6%
if -7.20000000000000018e-5 < eps < 1.04999999999999994e-5Initial program 36.0%
Taylor expanded in eps around 0 99.0%
if 1.04999999999999994e-5 < eps Initial program 54.7%
Final simplification75.1%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.4e-5) (not (<= eps 0.000105))) (sin eps) (* eps (cos x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.4e-5) || !(eps <= 0.000105)) {
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 <= (-1.4d-5)) .or. (.not. (eps <= 0.000105d0))) 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 <= -1.4e-5) || !(eps <= 0.000105)) {
tmp = Math.sin(eps);
} else {
tmp = eps * Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.4e-5) or not (eps <= 0.000105): tmp = math.sin(eps) else: tmp = eps * math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.4e-5) || !(eps <= 0.000105)) tmp = sin(eps); else tmp = Float64(eps * cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.4e-5) || ~((eps <= 0.000105))) tmp = sin(eps); else tmp = eps * cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.4e-5], N[Not[LessEqual[eps, 0.000105]], $MachinePrecision]], N[Sin[eps], $MachinePrecision], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.4 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 0.000105\right):\\
\;\;\;\;\sin \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\end{array}
\end{array}
if eps < -1.39999999999999998e-5 or 1.05e-4 < eps Initial program 51.9%
Taylor expanded in x around 0 52.1%
if -1.39999999999999998e-5 < eps < 1.05e-4Initial program 36.0%
Taylor expanded in eps around 0 99.0%
Final simplification74.9%
(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 44.2%
Taylor expanded in x around 0 55.9%
Final simplification55.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 44.2%
Taylor expanded in eps around 0 49.8%
Taylor expanded in x around 0 30.8%
Final simplification30.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 2023305
(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)))