
(FPCore (x eps) :precision binary64 (- (sin (+ x eps)) (sin x)))
double code(double x, double eps) {
return sin((x + eps)) - sin(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin((x + eps)) - sin(x)
end function
public static double code(double x, double eps) {
return Math.sin((x + eps)) - Math.sin(x);
}
def code(x, eps): return math.sin((x + eps)) - math.sin(x)
function code(x, eps) return Float64(sin(Float64(x + eps)) - sin(x)) end
function tmp = code(x, eps) tmp = sin((x + eps)) - sin(x); end
code[x_, eps_] := N[(N[Sin[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(x + \varepsilon\right) - \sin x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (sin (+ x eps)) (sin x)))
double code(double x, double eps) {
return sin((x + eps)) - sin(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin((x + eps)) - sin(x)
end function
public static double code(double x, double eps) {
return Math.sin((x + eps)) - Math.sin(x);
}
def code(x, eps): return math.sin((x + eps)) - math.sin(x)
function code(x, eps) return Float64(sin(Float64(x + eps)) - sin(x)) end
function tmp = code(x, eps) tmp = sin((x + eps)) - sin(x); end
code[x_, eps_] := N[(N[Sin[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(x + \varepsilon\right) - \sin x
\end{array}
(FPCore (x eps) :precision binary64 (fma (* (sin x) (sin eps)) (- (tan (/ eps 2.0))) (* (sin eps) (cos x))))
double code(double x, double eps) {
return fma((sin(x) * sin(eps)), -tan((eps / 2.0)), (sin(eps) * cos(x)));
}
function code(x, eps) return fma(Float64(sin(x) * sin(eps)), Float64(-tan(Float64(eps / 2.0))), Float64(sin(eps) * cos(x))) end
code[x_, eps_] := N[(N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] * (-N[Tan[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision]) + N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin x \cdot \sin \varepsilon, -\tan \left(\frac{\varepsilon}{2}\right), \sin \varepsilon \cdot \cos x\right)
\end{array}
Initial program 40.8%
sin-sum63.9%
associate--l+63.9%
Applied egg-rr63.9%
+-commutative63.9%
sub-neg63.9%
associate-+l+99.1%
*-commutative99.1%
neg-mul-199.1%
*-commutative99.1%
distribute-rgt-out99.1%
+-commutative99.1%
Simplified99.1%
flip-+99.0%
frac-2neg99.0%
metadata-eval99.0%
sub-1-cos99.4%
pow299.4%
sub-neg99.4%
metadata-eval99.4%
Applied egg-rr99.4%
remove-double-neg99.4%
neg-sub099.4%
+-commutative99.4%
associate--r+99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around inf 99.4%
associate-*r/99.4%
*-commutative99.4%
neg-mul-199.4%
distribute-lft-neg-in99.4%
associate-/l*99.4%
associate-/r/99.4%
distribute-neg-frac99.4%
neg-mul-199.4%
metadata-eval99.4%
times-frac99.4%
distribute-lft-in99.4%
neg-mul-199.4%
metadata-eval99.4%
+-commutative99.4%
sub-neg99.4%
*-lft-identity99.4%
Simplified99.5%
+-commutative99.5%
associate-*r*99.6%
fma-def99.6%
distribute-frac-neg99.6%
tan-neg99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- (sin (+ x eps)) (sin x)))) (if (or (<= t_0 -1e-7) (not (<= t_0 2e-299))) t_0 (* eps (cos x)))))
double code(double x, double eps) {
double t_0 = sin((x + eps)) - sin(x);
double tmp;
if ((t_0 <= -1e-7) || !(t_0 <= 2e-299)) {
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((x + eps)) - sin(x)
if ((t_0 <= (-1d-7)) .or. (.not. (t_0 <= 2d-299))) 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((x + eps)) - Math.sin(x);
double tmp;
if ((t_0 <= -1e-7) || !(t_0 <= 2e-299)) {
tmp = t_0;
} else {
tmp = eps * Math.cos(x);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((x + eps)) - math.sin(x) tmp = 0 if (t_0 <= -1e-7) or not (t_0 <= 2e-299): tmp = t_0 else: tmp = eps * math.cos(x) return tmp
function code(x, eps) t_0 = Float64(sin(Float64(x + eps)) - sin(x)) tmp = 0.0 if ((t_0 <= -1e-7) || !(t_0 <= 2e-299)) tmp = t_0; else tmp = Float64(eps * cos(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((x + eps)) - sin(x); tmp = 0.0; if ((t_0 <= -1e-7) || ~((t_0 <= 2e-299))) tmp = t_0; else tmp = eps * cos(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e-7], N[Not[LessEqual[t$95$0, 2e-299]], $MachinePrecision]], t$95$0, N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x + \varepsilon\right) - \sin x\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{-7} \lor \neg \left(t_0 \leq 2 \cdot 10^{-299}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\end{array}
\end{array}
if (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < -9.9999999999999995e-8 or 1.99999999999999998e-299 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) Initial program 73.2%
if -9.9999999999999995e-8 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < 1.99999999999999998e-299Initial program 16.7%
Taylor expanded in eps around 0 78.9%
Final simplification76.4%
(FPCore (x eps) :precision binary64 (fma (sin eps) (cos x) (* (* (sin x) (sin eps)) (- (tan (/ eps 2.0))))))
double code(double x, double eps) {
return fma(sin(eps), cos(x), ((sin(x) * sin(eps)) * -tan((eps / 2.0))));
}
function code(x, eps) return fma(sin(eps), cos(x), Float64(Float64(sin(x) * sin(eps)) * Float64(-tan(Float64(eps / 2.0))))) end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] * (-N[Tan[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin \varepsilon, \cos x, \left(\sin x \cdot \sin \varepsilon\right) \cdot \left(-\tan \left(\frac{\varepsilon}{2}\right)\right)\right)
\end{array}
Initial program 40.8%
sin-sum63.9%
associate--l+63.9%
Applied egg-rr63.9%
+-commutative63.9%
sub-neg63.9%
associate-+l+99.1%
*-commutative99.1%
neg-mul-199.1%
*-commutative99.1%
distribute-rgt-out99.1%
+-commutative99.1%
Simplified99.1%
flip-+99.0%
frac-2neg99.0%
metadata-eval99.0%
sub-1-cos99.4%
pow299.4%
sub-neg99.4%
metadata-eval99.4%
Applied egg-rr99.4%
remove-double-neg99.4%
neg-sub099.4%
+-commutative99.4%
associate--r+99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around inf 99.4%
associate-*r/99.4%
*-commutative99.4%
neg-mul-199.4%
distribute-lft-neg-in99.4%
associate-/l*99.4%
associate-/r/99.4%
distribute-neg-frac99.4%
neg-mul-199.4%
metadata-eval99.4%
times-frac99.4%
distribute-lft-in99.4%
neg-mul-199.4%
metadata-eval99.4%
+-commutative99.4%
sub-neg99.4%
*-lft-identity99.4%
Simplified99.5%
fma-def99.6%
associate-*r*99.6%
distribute-frac-neg99.6%
tan-neg99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (- (* (sin eps) (cos x)) (* (* (sin x) (sin eps)) (tan (/ eps 2.0)))))
double code(double x, double eps) {
return (sin(eps) * cos(x)) - ((sin(x) * sin(eps)) * tan((eps / 2.0)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (sin(eps) * cos(x)) - ((sin(x) * sin(eps)) * tan((eps / 2.0d0)))
end function
public static double code(double x, double eps) {
return (Math.sin(eps) * Math.cos(x)) - ((Math.sin(x) * Math.sin(eps)) * Math.tan((eps / 2.0)));
}
def code(x, eps): return (math.sin(eps) * math.cos(x)) - ((math.sin(x) * math.sin(eps)) * math.tan((eps / 2.0)))
function code(x, eps) return Float64(Float64(sin(eps) * cos(x)) - Float64(Float64(sin(x) * sin(eps)) * tan(Float64(eps / 2.0)))) end
function tmp = code(x, eps) tmp = (sin(eps) * cos(x)) - ((sin(x) * sin(eps)) * tan((eps / 2.0))); end
code[x_, eps_] := N[(N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] * N[Tan[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \varepsilon \cdot \cos x - \left(\sin x \cdot \sin \varepsilon\right) \cdot \tan \left(\frac{\varepsilon}{2}\right)
\end{array}
Initial program 40.8%
sin-sum63.9%
associate--l+63.9%
Applied egg-rr63.9%
+-commutative63.9%
sub-neg63.9%
associate-+l+99.1%
*-commutative99.1%
neg-mul-199.1%
*-commutative99.1%
distribute-rgt-out99.1%
+-commutative99.1%
Simplified99.1%
flip-+99.0%
frac-2neg99.0%
metadata-eval99.0%
sub-1-cos99.4%
pow299.4%
sub-neg99.4%
metadata-eval99.4%
Applied egg-rr99.4%
remove-double-neg99.4%
neg-sub099.4%
+-commutative99.4%
associate--r+99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around inf 99.4%
associate-*r/99.4%
*-commutative99.4%
neg-mul-199.4%
distribute-lft-neg-in99.4%
associate-/l*99.4%
associate-/r/99.4%
distribute-neg-frac99.4%
neg-mul-199.4%
metadata-eval99.4%
times-frac99.4%
distribute-lft-in99.4%
neg-mul-199.4%
metadata-eval99.4%
+-commutative99.4%
sub-neg99.4%
*-lft-identity99.4%
Simplified99.5%
expm1-log1p-u93.3%
expm1-udef47.4%
+-commutative47.4%
associate-*r*47.4%
fma-def47.4%
distribute-frac-neg47.4%
tan-neg47.4%
Applied egg-rr47.4%
expm1-def93.3%
expm1-log1p99.6%
fma-udef99.6%
+-commutative99.6%
distribute-rgt-neg-out99.6%
unsub-neg99.6%
*-commutative99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (fma (sin eps) (cos x) (* (sin x) (+ (cos eps) -1.0))))
double code(double x, double eps) {
return fma(sin(eps), cos(x), (sin(x) * (cos(eps) + -1.0)));
}
function code(x, eps) return fma(sin(eps), cos(x), Float64(sin(x) * Float64(cos(eps) + -1.0))) end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin \varepsilon, \cos x, \sin x \cdot \left(\cos \varepsilon + -1\right)\right)
\end{array}
Initial program 40.8%
sin-sum63.9%
associate--l+63.9%
Applied egg-rr63.9%
+-commutative63.9%
sub-neg63.9%
associate-+l+99.1%
*-commutative99.1%
neg-mul-199.1%
*-commutative99.1%
distribute-rgt-out99.1%
+-commutative99.1%
Simplified99.1%
fma-def99.1%
*-commutative99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (fma (+ (cos eps) -1.0) (sin x) (* (sin eps) (cos x))))
double code(double x, double eps) {
return fma((cos(eps) + -1.0), sin(x), (sin(eps) * cos(x)));
}
function code(x, eps) return fma(Float64(cos(eps) + -1.0), sin(x), Float64(sin(eps) * cos(x))) end
code[x_, eps_] := N[(N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision] * N[Sin[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos \varepsilon + -1, \sin x, \sin \varepsilon \cdot \cos x\right)
\end{array}
Initial program 40.8%
sin-sum63.9%
associate--l+63.9%
Applied egg-rr63.9%
+-commutative63.9%
sub-neg63.9%
associate-+l+99.1%
*-commutative99.1%
neg-mul-199.1%
*-commutative99.1%
distribute-rgt-out99.1%
+-commutative99.1%
Simplified99.1%
+-commutative99.1%
*-commutative99.1%
*-commutative99.1%
fma-def99.1%
*-commutative99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (+ (* (sin eps) (cos x)) (* (sin x) (+ (cos eps) -1.0))))
double code(double x, double eps) {
return (sin(eps) * cos(x)) + (sin(x) * (cos(eps) + -1.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (sin(eps) * cos(x)) + (sin(x) * (cos(eps) + (-1.0d0)))
end function
public static double code(double x, double eps) {
return (Math.sin(eps) * Math.cos(x)) + (Math.sin(x) * (Math.cos(eps) + -1.0));
}
def code(x, eps): return (math.sin(eps) * math.cos(x)) + (math.sin(x) * (math.cos(eps) + -1.0))
function code(x, eps) return Float64(Float64(sin(eps) * cos(x)) + Float64(sin(x) * Float64(cos(eps) + -1.0))) end
function tmp = code(x, eps) tmp = (sin(eps) * cos(x)) + (sin(x) * (cos(eps) + -1.0)); end
code[x_, eps_] := N[(N[(N[Sin[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \varepsilon \cdot \cos x + \sin x \cdot \left(\cos \varepsilon + -1\right)
\end{array}
Initial program 40.8%
sin-sum63.9%
associate--l+63.9%
Applied egg-rr63.9%
+-commutative63.9%
sub-neg63.9%
associate-+l+99.1%
*-commutative99.1%
neg-mul-199.1%
*-commutative99.1%
distribute-rgt-out99.1%
+-commutative99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.00074)
(sin eps)
(if (<= eps 1.7e-7)
(* eps (+ (cos x) (* (sin x) (* eps -0.5))))
(sin eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.00074) {
tmp = sin(eps);
} else if (eps <= 1.7e-7) {
tmp = eps * (cos(x) + (sin(x) * (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) :: tmp
if (eps <= (-0.00074d0)) then
tmp = sin(eps)
else if (eps <= 1.7d-7) then
tmp = eps * (cos(x) + (sin(x) * (eps * (-0.5d0))))
else
tmp = sin(eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -0.00074) {
tmp = Math.sin(eps);
} else if (eps <= 1.7e-7) {
tmp = eps * (Math.cos(x) + (Math.sin(x) * (eps * -0.5)));
} else {
tmp = Math.sin(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.00074: tmp = math.sin(eps) elif eps <= 1.7e-7: tmp = eps * (math.cos(x) + (math.sin(x) * (eps * -0.5))) else: tmp = math.sin(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.00074) tmp = sin(eps); elseif (eps <= 1.7e-7) tmp = Float64(eps * Float64(cos(x) + Float64(sin(x) * Float64(eps * -0.5)))); else tmp = sin(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -0.00074) tmp = sin(eps); elseif (eps <= 1.7e-7) tmp = eps * (cos(x) + (sin(x) * (eps * -0.5))); else tmp = sin(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.00074], N[Sin[eps], $MachinePrecision], If[LessEqual[eps, 1.7e-7], N[(eps * N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00074:\\
\;\;\;\;\sin \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 1.7 \cdot 10^{-7}:\\
\;\;\;\;\varepsilon \cdot \left(\cos x + \sin x \cdot \left(\varepsilon \cdot -0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \varepsilon\\
\end{array}
\end{array}
if eps < -7.3999999999999999e-4 or 1.69999999999999987e-7 < eps Initial program 54.4%
Taylor expanded in x around 0 54.7%
if -7.3999999999999999e-4 < eps < 1.69999999999999987e-7Initial program 26.9%
sin-sum28.1%
associate--l+28.1%
Applied egg-rr28.1%
+-commutative28.1%
sub-neg28.1%
associate-+l+98.9%
*-commutative98.9%
neg-mul-198.9%
*-commutative98.9%
distribute-rgt-out98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in eps around 0 99.4%
fma-def99.4%
unpow299.4%
Simplified99.4%
Taylor expanded in x around inf 99.4%
*-commutative99.4%
associate-*r*99.4%
unpow299.4%
associate-*l*99.4%
*-commutative99.4%
associate-*r*99.4%
distribute-rgt-out99.4%
*-commutative99.4%
Simplified99.4%
Final simplification76.9%
(FPCore (x eps) :precision binary64 (* 2.0 (* (sin (* eps 0.5)) (cos (* 0.5 (+ eps (+ x x)))))))
double code(double x, double eps) {
return 2.0 * (sin((eps * 0.5)) * cos((0.5 * (eps + (x + x)))));
}
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 + x)))))
end function
public static double code(double x, double eps) {
return 2.0 * (Math.sin((eps * 0.5)) * Math.cos((0.5 * (eps + (x + x)))));
}
def code(x, eps): return 2.0 * (math.sin((eps * 0.5)) * math.cos((0.5 * (eps + (x + x)))))
function code(x, eps) return Float64(2.0 * Float64(sin(Float64(eps * 0.5)) * cos(Float64(0.5 * Float64(eps + Float64(x + x)))))) end
function tmp = code(x, eps) tmp = 2.0 * (sin((eps * 0.5)) * cos((0.5 * (eps + (x + x))))); 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 + x), $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 + \left(x + x\right)\right)\right)\right)
\end{array}
Initial program 40.8%
sin-sum63.9%
associate--l+63.9%
Applied egg-rr63.9%
+-commutative63.9%
sub-neg63.9%
associate-+l+99.1%
*-commutative99.1%
neg-mul-199.1%
*-commutative99.1%
distribute-rgt-out99.1%
+-commutative99.1%
Simplified99.1%
*-commutative99.1%
distribute-lft-in99.1%
associate-+r+63.9%
+-commutative63.9%
*-commutative63.9%
neg-mul-163.9%
sin-sum40.8%
sub-neg40.8%
diff-sin40.1%
div-inv40.1%
+-commutative40.1%
associate--l+76.4%
metadata-eval76.4%
div-inv76.4%
associate-+l+76.4%
metadata-eval76.4%
Applied egg-rr76.4%
+-inverses76.4%
+-rgt-identity76.4%
*-commutative76.4%
+-commutative76.4%
associate-+l+76.4%
Simplified76.4%
Final simplification76.4%
(FPCore (x eps) :precision binary64 (if (<= eps -0.00075) (sin eps) (if (<= eps 1.7e-7) (* eps (cos x)) (sin eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.00075) {
tmp = sin(eps);
} else if (eps <= 1.7e-7) {
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.00075d0)) then
tmp = sin(eps)
else if (eps <= 1.7d-7) 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.00075) {
tmp = Math.sin(eps);
} else if (eps <= 1.7e-7) {
tmp = eps * Math.cos(x);
} else {
tmp = Math.sin(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.00075: tmp = math.sin(eps) elif eps <= 1.7e-7: tmp = eps * math.cos(x) else: tmp = math.sin(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.00075) tmp = sin(eps); elseif (eps <= 1.7e-7) 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.00075) tmp = sin(eps); elseif (eps <= 1.7e-7) tmp = eps * cos(x); else tmp = sin(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.00075], N[Sin[eps], $MachinePrecision], If[LessEqual[eps, 1.7e-7], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision], N[Sin[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00075:\\
\;\;\;\;\sin \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 1.7 \cdot 10^{-7}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin \varepsilon\\
\end{array}
\end{array}
if eps < -7.5000000000000002e-4 or 1.69999999999999987e-7 < eps Initial program 54.4%
Taylor expanded in x around 0 54.7%
if -7.5000000000000002e-4 < eps < 1.69999999999999987e-7Initial program 26.9%
Taylor expanded in eps around 0 98.4%
Final simplification76.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 40.8%
Taylor expanded in x around 0 50.6%
Final simplification50.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 40.8%
Taylor expanded in eps around 0 51.1%
Taylor expanded in x around 0 25.4%
Final simplification25.4%
(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 2023230
(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)))