
(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 13 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)))) (* t_0 (* 2.0 (fma (cos x) (cos (* eps 0.5)) (- (* (sin x) t_0)))))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
return t_0 * (2.0 * fma(cos(x), cos((eps * 0.5)), -(sin(x) * t_0)));
}
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) return Float64(t_0 * Float64(2.0 * fma(cos(x), cos(Float64(eps * 0.5)), Float64(-Float64(sin(x) * t_0))))) end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 * N[(2.0 * N[(N[Cos[x], $MachinePrecision] * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] + (-N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
t_0 \cdot \left(2 \cdot \mathsf{fma}\left(\cos x, \cos \left(\varepsilon \cdot 0.5\right), -\sin x \cdot t_0\right)\right)
\end{array}
\end{array}
Initial program 40.2%
diff-sin39.8%
div-inv39.8%
metadata-eval39.8%
div-inv39.8%
+-commutative39.8%
metadata-eval39.8%
Applied egg-rr39.8%
associate-*r*39.8%
*-commutative39.8%
associate-*l*39.8%
+-commutative39.8%
associate--l+75.7%
+-inverses75.7%
*-commutative75.7%
associate-+r+75.5%
+-commutative75.5%
Simplified75.5%
distribute-lft-in75.5%
*-commutative75.5%
+-rgt-identity75.5%
cos-sum99.4%
+-rgt-identity99.4%
*-commutative99.4%
+-rgt-identity99.4%
*-commutative99.4%
Applied egg-rr99.4%
*-commutative99.4%
count-299.4%
associate-*r*99.4%
metadata-eval99.4%
*-lft-identity99.4%
*-commutative99.4%
*-commutative99.4%
count-299.4%
associate-*r*99.4%
metadata-eval99.4%
*-lft-identity99.4%
*-commutative99.4%
Simplified99.4%
fma-neg99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (+ eps x))) (t_1 (- t_0 (sin x))))
(if (or (<= t_1 -0.0512) (not (<= t_1 1e-106)))
(- t_0 (+ -1.0 (+ (sin x) 1.0)))
(* (sin (* eps 0.5)) (* 2.0 (cos x))))))
double code(double x, double eps) {
double t_0 = sin((eps + x));
double t_1 = t_0 - sin(x);
double tmp;
if ((t_1 <= -0.0512) || !(t_1 <= 1e-106)) {
tmp = t_0 - (-1.0 + (sin(x) + 1.0));
} else {
tmp = sin((eps * 0.5)) * (2.0 * 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) :: t_1
real(8) :: tmp
t_0 = sin((eps + x))
t_1 = t_0 - sin(x)
if ((t_1 <= (-0.0512d0)) .or. (.not. (t_1 <= 1d-106))) then
tmp = t_0 - ((-1.0d0) + (sin(x) + 1.0d0))
else
tmp = sin((eps * 0.5d0)) * (2.0d0 * cos(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps + x));
double t_1 = t_0 - Math.sin(x);
double tmp;
if ((t_1 <= -0.0512) || !(t_1 <= 1e-106)) {
tmp = t_0 - (-1.0 + (Math.sin(x) + 1.0));
} else {
tmp = Math.sin((eps * 0.5)) * (2.0 * Math.cos(x));
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps + x)) t_1 = t_0 - math.sin(x) tmp = 0 if (t_1 <= -0.0512) or not (t_1 <= 1e-106): tmp = t_0 - (-1.0 + (math.sin(x) + 1.0)) else: tmp = math.sin((eps * 0.5)) * (2.0 * math.cos(x)) return tmp
function code(x, eps) t_0 = sin(Float64(eps + x)) t_1 = Float64(t_0 - sin(x)) tmp = 0.0 if ((t_1 <= -0.0512) || !(t_1 <= 1e-106)) tmp = Float64(t_0 - Float64(-1.0 + Float64(sin(x) + 1.0))); else tmp = Float64(sin(Float64(eps * 0.5)) * Float64(2.0 * cos(x))); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps + x)); t_1 = t_0 - sin(x); tmp = 0.0; if ((t_1 <= -0.0512) || ~((t_1 <= 1e-106))) tmp = t_0 - (-1.0 + (sin(x) + 1.0)); else tmp = sin((eps * 0.5)) * (2.0 * cos(x)); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -0.0512], N[Not[LessEqual[t$95$1, 1e-106]], $MachinePrecision]], N[(t$95$0 - N[(-1.0 + N[(N[Sin[x], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[(2.0 * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon + x\right)\\
t_1 := t_0 - \sin x\\
\mathbf{if}\;t_1 \leq -0.0512 \lor \neg \left(t_1 \leq 10^{-106}\right):\\
\;\;\;\;t_0 - \left(-1 + \left(\sin x + 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\varepsilon \cdot 0.5\right) \cdot \left(2 \cdot \cos x\right)\\
\end{array}
\end{array}
if (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < -0.0512000000000000025 or 9.99999999999999941e-107 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) Initial program 67.4%
expm1-log1p-u67.4%
Applied egg-rr67.4%
expm1-udef67.4%
log1p-udef67.4%
add-exp-log67.4%
Applied egg-rr67.4%
if -0.0512000000000000025 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < 9.99999999999999941e-107Initial program 22.8%
diff-sin22.7%
div-inv22.7%
metadata-eval22.7%
div-inv22.7%
+-commutative22.7%
metadata-eval22.7%
Applied egg-rr22.7%
associate-*r*22.7%
*-commutative22.7%
associate-*l*22.7%
+-commutative22.7%
associate--l+81.8%
+-inverses81.8%
*-commutative81.8%
associate-+r+81.8%
+-commutative81.8%
Simplified81.8%
Taylor expanded in eps around 0 82.2%
Final simplification76.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (sin (+ eps x)) (sin x))))
(if (or (<= t_0 -0.0512) (not (<= t_0 1e-106)))
t_0
(* (sin (* eps 0.5)) (* 2.0 (cos x))))))
double code(double x, double eps) {
double t_0 = sin((eps + x)) - sin(x);
double tmp;
if ((t_0 <= -0.0512) || !(t_0 <= 1e-106)) {
tmp = t_0;
} else {
tmp = sin((eps * 0.5)) * (2.0 * 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 <= (-0.0512d0)) .or. (.not. (t_0 <= 1d-106))) then
tmp = t_0
else
tmp = sin((eps * 0.5d0)) * (2.0d0 * 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 <= -0.0512) || !(t_0 <= 1e-106)) {
tmp = t_0;
} else {
tmp = Math.sin((eps * 0.5)) * (2.0 * Math.cos(x));
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps + x)) - math.sin(x) tmp = 0 if (t_0 <= -0.0512) or not (t_0 <= 1e-106): tmp = t_0 else: tmp = math.sin((eps * 0.5)) * (2.0 * math.cos(x)) return tmp
function code(x, eps) t_0 = Float64(sin(Float64(eps + x)) - sin(x)) tmp = 0.0 if ((t_0 <= -0.0512) || !(t_0 <= 1e-106)) tmp = t_0; else tmp = Float64(sin(Float64(eps * 0.5)) * Float64(2.0 * 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 <= -0.0512) || ~((t_0 <= 1e-106))) tmp = t_0; else tmp = sin((eps * 0.5)) * (2.0 * 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, -0.0512], N[Not[LessEqual[t$95$0, 1e-106]], $MachinePrecision]], t$95$0, N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[(2.0 * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon + x\right) - \sin x\\
\mathbf{if}\;t_0 \leq -0.0512 \lor \neg \left(t_0 \leq 10^{-106}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\varepsilon \cdot 0.5\right) \cdot \left(2 \cdot \cos x\right)\\
\end{array}
\end{array}
if (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < -0.0512000000000000025 or 9.99999999999999941e-107 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) Initial program 67.4%
if -0.0512000000000000025 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < 9.99999999999999941e-107Initial program 22.8%
diff-sin22.7%
div-inv22.7%
metadata-eval22.7%
div-inv22.7%
+-commutative22.7%
metadata-eval22.7%
Applied egg-rr22.7%
associate-*r*22.7%
*-commutative22.7%
associate-*l*22.7%
+-commutative22.7%
associate--l+81.8%
+-inverses81.8%
*-commutative81.8%
associate-+r+81.8%
+-commutative81.8%
Simplified81.8%
Taylor expanded in eps around 0 82.2%
Final simplification76.4%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- (sin (+ eps x)) (sin x)))) (if (or (<= t_0 -0.02) (not (<= t_0 1e-106))) t_0 (* eps (cos x)))))
double code(double x, double eps) {
double t_0 = sin((eps + x)) - sin(x);
double tmp;
if ((t_0 <= -0.02) || !(t_0 <= 1e-106)) {
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 <= (-0.02d0)) .or. (.not. (t_0 <= 1d-106))) 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 <= -0.02) || !(t_0 <= 1e-106)) {
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 <= -0.02) or not (t_0 <= 1e-106): 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 <= -0.02) || !(t_0 <= 1e-106)) 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 <= -0.02) || ~((t_0 <= 1e-106))) 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, -0.02], N[Not[LessEqual[t$95$0, 1e-106]], $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 -0.02 \lor \neg \left(t_0 \leq 10^{-106}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\end{array}
\end{array}
if (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < -0.0200000000000000004 or 9.99999999999999941e-107 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) Initial program 65.8%
if -0.0200000000000000004 < (-.f64 (sin.f64 (+.f64 x eps)) (sin.f64 x)) < 9.99999999999999941e-107Initial program 23.0%
Taylor expanded in eps around 0 82.2%
Final simplification75.6%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* eps 0.5)))) (* 2.0 (* t_0 (- (* (cos x) (cos (* eps 0.5))) (* (sin x) t_0))))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
return 2.0 * (t_0 * ((cos(x) * cos((eps * 0.5))) - (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 = 2.0d0 * (t_0 * ((cos(x) * cos((eps * 0.5d0))) - (sin(x) * t_0)))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
return 2.0 * (t_0 * ((Math.cos(x) * Math.cos((eps * 0.5))) - (Math.sin(x) * t_0)));
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) return 2.0 * (t_0 * ((math.cos(x) * math.cos((eps * 0.5))) - (math.sin(x) * t_0)))
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) return Float64(2.0 * Float64(t_0 * Float64(Float64(cos(x) * cos(Float64(eps * 0.5))) - Float64(sin(x) * t_0)))) end
function tmp = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 2.0 * (t_0 * ((cos(x) * cos((eps * 0.5))) - (sin(x) * t_0))); end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(2.0 * N[(t$95$0 * N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
2 \cdot \left(t_0 \cdot \left(\cos x \cdot \cos \left(\varepsilon \cdot 0.5\right) - \sin x \cdot t_0\right)\right)
\end{array}
\end{array}
Initial program 40.2%
diff-sin39.8%
div-inv39.8%
metadata-eval39.8%
div-inv39.8%
+-commutative39.8%
metadata-eval39.8%
Applied egg-rr39.8%
associate-*r*39.8%
*-commutative39.8%
associate-*l*39.8%
+-commutative39.8%
associate--l+75.7%
+-inverses75.7%
*-commutative75.7%
associate-+r+75.5%
+-commutative75.5%
Simplified75.5%
distribute-lft-in75.5%
*-commutative75.5%
+-rgt-identity75.5%
cos-sum99.4%
+-rgt-identity99.4%
*-commutative99.4%
+-rgt-identity99.4%
*-commutative99.4%
Applied egg-rr99.4%
*-commutative99.4%
count-299.4%
associate-*r*99.4%
metadata-eval99.4%
*-lft-identity99.4%
*-commutative99.4%
*-commutative99.4%
count-299.4%
associate-*r*99.4%
metadata-eval99.4%
*-lft-identity99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in eps around inf 99.4%
*-commutative99.4%
*-commutative99.4%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
Final simplification99.4%
(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 40.2%
sin-sum64.6%
Applied egg-rr64.6%
Taylor expanded in x around inf 64.6%
associate--l+99.4%
fma-def99.4%
*-lft-identity99.4%
distribute-rgt-out--99.4%
sub-neg99.4%
metadata-eval99.4%
+-commutative99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (+ (* (cos x) (sin eps)) (* (sin x) (+ -1.0 (cos eps)))))
double code(double x, double eps) {
return (cos(x) * sin(eps)) + (sin(x) * (-1.0 + cos(eps)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (cos(x) * sin(eps)) + (sin(x) * ((-1.0d0) + cos(eps)))
end function
public static double code(double x, double eps) {
return (Math.cos(x) * Math.sin(eps)) + (Math.sin(x) * (-1.0 + Math.cos(eps)));
}
def code(x, eps): return (math.cos(x) * math.sin(eps)) + (math.sin(x) * (-1.0 + math.cos(eps)))
function code(x, eps) return Float64(Float64(cos(x) * sin(eps)) + Float64(sin(x) * Float64(-1.0 + cos(eps)))) end
function tmp = code(x, eps) tmp = (cos(x) * sin(eps)) + (sin(x) * (-1.0 + cos(eps))); end
code[x_, eps_] := N[(N[(N[Cos[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \sin \varepsilon + \sin x \cdot \left(-1 + \cos \varepsilon\right)
\end{array}
Initial program 40.2%
sin-sum64.6%
Applied egg-rr64.6%
Taylor expanded in x around inf 64.6%
associate--l+99.4%
fma-def99.4%
*-lft-identity99.4%
distribute-rgt-out--99.4%
sub-neg99.4%
metadata-eval99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in x around inf 99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (* 2.0 (* (sin (* eps 0.5)) (cos (* 0.5 (+ eps (* 2.0 x)))))))
double code(double x, double eps) {
return 2.0 * (sin((eps * 0.5)) * cos((0.5 * (eps + (2.0 * 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 + (2.0d0 * x)))))
end function
public static double code(double x, double eps) {
return 2.0 * (Math.sin((eps * 0.5)) * Math.cos((0.5 * (eps + (2.0 * x)))));
}
def code(x, eps): return 2.0 * (math.sin((eps * 0.5)) * math.cos((0.5 * (eps + (2.0 * x)))))
function code(x, eps) return Float64(2.0 * Float64(sin(Float64(eps * 0.5)) * cos(Float64(0.5 * Float64(eps + Float64(2.0 * x)))))) end
function tmp = code(x, eps) tmp = 2.0 * (sin((eps * 0.5)) * cos((0.5 * (eps + (2.0 * 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[(2.0 * 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 + 2 \cdot x\right)\right)\right)
\end{array}
Initial program 40.2%
diff-sin39.8%
div-inv39.8%
metadata-eval39.8%
div-inv39.8%
+-commutative39.8%
metadata-eval39.8%
Applied egg-rr39.8%
associate-*r*39.8%
*-commutative39.8%
associate-*l*39.8%
+-commutative39.8%
associate--l+75.7%
+-inverses75.7%
*-commutative75.7%
associate-+r+75.5%
+-commutative75.5%
Simplified75.5%
Taylor expanded in eps around inf 75.5%
Final simplification75.5%
(FPCore (x eps) :precision binary64 (* (cos (/ (+ x (+ eps x)) 2.0)) (* 2.0 (sin (/ eps 2.0)))))
double code(double x, double eps) {
return cos(((x + (eps + x)) / 2.0)) * (2.0 * sin((eps / 2.0)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos(((x + (eps + x)) / 2.0d0)) * (2.0d0 * sin((eps / 2.0d0)))
end function
public static double code(double x, double eps) {
return Math.cos(((x + (eps + x)) / 2.0)) * (2.0 * Math.sin((eps / 2.0)));
}
def code(x, eps): return math.cos(((x + (eps + x)) / 2.0)) * (2.0 * math.sin((eps / 2.0)))
function code(x, eps) return Float64(cos(Float64(Float64(x + Float64(eps + x)) / 2.0)) * Float64(2.0 * sin(Float64(eps / 2.0)))) end
function tmp = code(x, eps) tmp = cos(((x + (eps + x)) / 2.0)) * (2.0 * sin((eps / 2.0))); end
code[x_, eps_] := N[(N[Cos[N[(N[(x + N[(eps + x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[(2.0 * N[Sin[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(\frac{x + \left(\varepsilon + x\right)}{2}\right) \cdot \left(2 \cdot \sin \left(\frac{\varepsilon}{2}\right)\right)
\end{array}
Initial program 40.2%
expm1-log1p-u40.2%
Applied egg-rr40.2%
expm1-log1p-u40.2%
diff-sin39.8%
+-commutative39.8%
+-commutative39.8%
Applied egg-rr39.8%
associate-*r*39.8%
*-commutative39.8%
+-commutative39.8%
+-commutative39.8%
associate--l+75.7%
+-inverses75.7%
+-rgt-identity75.7%
Simplified75.7%
Final simplification75.7%
(FPCore (x eps) :precision binary64 (if (<= eps -4.5e-5) (sin eps) (if (<= eps 6.9e-18) (* eps (cos x)) (sin eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -4.5e-5) {
tmp = sin(eps);
} else if (eps <= 6.9e-18) {
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 <= (-4.5d-5)) then
tmp = sin(eps)
else if (eps <= 6.9d-18) 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 <= -4.5e-5) {
tmp = Math.sin(eps);
} else if (eps <= 6.9e-18) {
tmp = eps * Math.cos(x);
} else {
tmp = Math.sin(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -4.5e-5: tmp = math.sin(eps) elif eps <= 6.9e-18: tmp = eps * math.cos(x) else: tmp = math.sin(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -4.5e-5) tmp = sin(eps); elseif (eps <= 6.9e-18) tmp = Float64(eps * cos(x)); else tmp = sin(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -4.5e-5) tmp = sin(eps); elseif (eps <= 6.9e-18) tmp = eps * cos(x); else tmp = sin(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -4.5e-5], N[Sin[eps], $MachinePrecision], If[LessEqual[eps, 6.9e-18], N[(eps * N[Cos[x], $MachinePrecision]), $MachinePrecision], N[Sin[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.5 \cdot 10^{-5}:\\
\;\;\;\;\sin \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 6.9 \cdot 10^{-18}:\\
\;\;\;\;\varepsilon \cdot \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin \varepsilon\\
\end{array}
\end{array}
if eps < -4.50000000000000028e-5 or 6.9000000000000003e-18 < eps Initial program 51.3%
Taylor expanded in x around 0 51.3%
if -4.50000000000000028e-5 < eps < 6.9000000000000003e-18Initial program 29.2%
Taylor expanded in eps around 0 99.4%
Final simplification75.3%
(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.2%
Taylor expanded in x around 0 51.4%
Final simplification51.4%
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
return 0.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
public static double code(double x, double eps) {
return 0.0;
}
def code(x, eps): return 0.0
function code(x, eps) return 0.0 end
function tmp = code(x, eps) tmp = 0.0; end
code[x_, eps_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 40.2%
add-cube-cbrt40.0%
pow339.9%
Applied egg-rr39.9%
Taylor expanded in eps around 0 4.3%
pow-base-14.3%
*-lft-identity4.3%
+-inverses4.3%
Simplified4.3%
Final simplification4.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 40.2%
Taylor expanded in eps around 0 52.5%
fma-def52.5%
*-commutative52.5%
unpow252.5%
Simplified52.5%
Taylor expanded in x around 0 28.3%
Final simplification28.3%
(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 2023187
(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)))