
(FPCore (a b) :precision binary64 (* (* (/ PI 2.0) (/ 1.0 (- (* b b) (* a a)))) (- (/ 1.0 a) (/ 1.0 b))))
double code(double a, double b) {
return ((((double) M_PI) / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
public static double code(double a, double b) {
return ((Math.PI / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
def code(a, b): return ((math.pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b))
function code(a, b) return Float64(Float64(Float64(pi / 2.0) * Float64(1.0 / Float64(Float64(b * b) - Float64(a * a)))) * Float64(Float64(1.0 / a) - Float64(1.0 / b))) end
function tmp = code(a, b) tmp = ((pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b)); end
code[a_, b_] := N[(N[(N[(Pi / 2.0), $MachinePrecision] * N[(1.0 / N[(N[(b * b), $MachinePrecision] - N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / a), $MachinePrecision] - N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (* (* (/ PI 2.0) (/ 1.0 (- (* b b) (* a a)))) (- (/ 1.0 a) (/ 1.0 b))))
double code(double a, double b) {
return ((((double) M_PI) / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
public static double code(double a, double b) {
return ((Math.PI / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
def code(a, b): return ((math.pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b))
function code(a, b) return Float64(Float64(Float64(pi / 2.0) * Float64(1.0 / Float64(Float64(b * b) - Float64(a * a)))) * Float64(Float64(1.0 / a) - Float64(1.0 / b))) end
function tmp = code(a, b) tmp = ((pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b)); end
code[a_, b_] := N[(N[(N[(Pi / 2.0), $MachinePrecision] * N[(1.0 / N[(N[(b * b), $MachinePrecision] - N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / a), $MachinePrecision] - N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right)
\end{array}
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ (/ (/ PI a) b) (* 2.0 (+ a b))))
assert(a < b);
double code(double a, double b) {
return ((((double) M_PI) / a) / b) / (2.0 * (a + b));
}
assert a < b;
public static double code(double a, double b) {
return ((Math.PI / a) / b) / (2.0 * (a + b));
}
[a, b] = sort([a, b]) def code(a, b): return ((math.pi / a) / b) / (2.0 * (a + b))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(Float64(pi / a) / b) / Float64(2.0 * Float64(a + b))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = ((pi / a) / b) / (2.0 * (a + b));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(N[(Pi / a), $MachinePrecision] / b), $MachinePrecision] / N[(2.0 * N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{\frac{\pi}{a}}{b}}{2 \cdot \left(a + b\right)}
\end{array}
Initial program 79.0%
associate-*r/79.0%
*-rgt-identity79.0%
associate-*l/79.0%
difference-of-squares85.2%
times-frac99.7%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
associate-*l/99.6%
add-sqr-sqrt49.0%
sqrt-unprod76.4%
frac-times76.4%
metadata-eval76.4%
metadata-eval76.4%
frac-times76.4%
sqrt-unprod34.8%
add-sqr-sqrt66.0%
*-commutative66.0%
Applied egg-rr66.0%
Taylor expanded in a around 0 99.7%
associate-/r*99.7%
Simplified99.7%
Final simplification99.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -8.5e-47) (/ 0.5 (* (* a b) (/ a PI))) (/ 0.5 (* b (* a (/ b PI))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -8.5e-47) {
tmp = 0.5 / ((a * b) * (a / ((double) M_PI)));
} else {
tmp = 0.5 / (b * (a * (b / ((double) M_PI))));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -8.5e-47) {
tmp = 0.5 / ((a * b) * (a / Math.PI));
} else {
tmp = 0.5 / (b * (a * (b / Math.PI)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -8.5e-47: tmp = 0.5 / ((a * b) * (a / math.pi)) else: tmp = 0.5 / (b * (a * (b / math.pi))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -8.5e-47) tmp = Float64(0.5 / Float64(Float64(a * b) * Float64(a / pi))); else tmp = Float64(0.5 / Float64(b * Float64(a * Float64(b / pi)))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -8.5e-47)
tmp = 0.5 / ((a * b) * (a / pi));
else
tmp = 0.5 / (b * (a * (b / pi)));
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -8.5e-47], N[(0.5 / N[(N[(a * b), $MachinePrecision] * N[(a / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(b * N[(a * N[(b / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -8.5 \cdot 10^{-47}:\\
\;\;\;\;\frac{0.5}{\left(a \cdot b\right) \cdot \frac{a}{\pi}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{b \cdot \left(a \cdot \frac{b}{\pi}\right)}\\
\end{array}
\end{array}
if a < -8.4999999999999999e-47Initial program 82.0%
associate-*r/82.1%
*-rgt-identity82.1%
associate-*l/82.0%
difference-of-squares89.4%
times-frac99.7%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.6%
associate-/r*99.7%
Simplified99.7%
Taylor expanded in b around 0 84.7%
associate-*r/84.7%
Simplified84.7%
associate-/l*84.6%
associate-/r*84.6%
frac-times82.7%
metadata-eval82.7%
Applied egg-rr82.7%
if -8.4999999999999999e-47 < a Initial program 77.9%
associate-*r/77.9%
*-rgt-identity77.9%
associate-*l/77.9%
difference-of-squares83.7%
times-frac99.6%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 99.7%
associate-/r*99.6%
Simplified99.6%
Taylor expanded in b around inf 68.9%
*-commutative68.9%
associate-/l/68.9%
*-commutative68.9%
associate-*r/68.9%
*-commutative68.9%
frac-times68.7%
*-un-lft-identity68.7%
times-frac68.9%
clear-num68.8%
frac-times68.7%
metadata-eval68.7%
*-un-lft-identity68.7%
times-frac68.7%
/-rgt-identity68.7%
Applied egg-rr68.7%
Final simplification72.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -2e-46) (/ 0.5 (* (* a b) (/ a PI))) (/ (* (/ (/ PI a) b) 0.5) b)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -2e-46) {
tmp = 0.5 / ((a * b) * (a / ((double) M_PI)));
} else {
tmp = (((((double) M_PI) / a) / b) * 0.5) / b;
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -2e-46) {
tmp = 0.5 / ((a * b) * (a / Math.PI));
} else {
tmp = (((Math.PI / a) / b) * 0.5) / b;
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -2e-46: tmp = 0.5 / ((a * b) * (a / math.pi)) else: tmp = (((math.pi / a) / b) * 0.5) / b return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -2e-46) tmp = Float64(0.5 / Float64(Float64(a * b) * Float64(a / pi))); else tmp = Float64(Float64(Float64(Float64(pi / a) / b) * 0.5) / b); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -2e-46)
tmp = 0.5 / ((a * b) * (a / pi));
else
tmp = (((pi / a) / b) * 0.5) / b;
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -2e-46], N[(0.5 / N[(N[(a * b), $MachinePrecision] * N[(a / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(Pi / a), $MachinePrecision] / b), $MachinePrecision] * 0.5), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2 \cdot 10^{-46}:\\
\;\;\;\;\frac{0.5}{\left(a \cdot b\right) \cdot \frac{a}{\pi}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{\pi}{a}}{b} \cdot 0.5}{b}\\
\end{array}
\end{array}
if a < -2.00000000000000005e-46Initial program 82.0%
associate-*r/82.1%
*-rgt-identity82.1%
associate-*l/82.0%
difference-of-squares89.4%
times-frac99.7%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.6%
associate-/r*99.7%
Simplified99.7%
Taylor expanded in b around 0 84.7%
associate-*r/84.7%
Simplified84.7%
associate-/l*84.6%
associate-/r*84.6%
frac-times82.7%
metadata-eval82.7%
Applied egg-rr82.7%
if -2.00000000000000005e-46 < a Initial program 77.9%
associate-*r/77.9%
*-rgt-identity77.9%
associate-*l/77.9%
difference-of-squares83.7%
times-frac99.6%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 99.7%
associate-/r*99.6%
Simplified99.6%
Taylor expanded in b around inf 68.9%
*-commutative68.9%
associate-/l/68.9%
*-commutative68.9%
associate-*r/68.9%
*-commutative68.9%
frac-times68.7%
*-un-lft-identity68.7%
associate-/r*68.9%
*-commutative68.9%
*-un-lft-identity68.9%
times-frac68.9%
metadata-eval68.9%
associate-/r*68.9%
Applied egg-rr68.9%
Final simplification72.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -2e-46) (/ (/ PI a) (* 2.0 (* a b))) (/ (* (/ (/ PI a) b) 0.5) b)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -2e-46) {
tmp = (((double) M_PI) / a) / (2.0 * (a * b));
} else {
tmp = (((((double) M_PI) / a) / b) * 0.5) / b;
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -2e-46) {
tmp = (Math.PI / a) / (2.0 * (a * b));
} else {
tmp = (((Math.PI / a) / b) * 0.5) / b;
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -2e-46: tmp = (math.pi / a) / (2.0 * (a * b)) else: tmp = (((math.pi / a) / b) * 0.5) / b return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -2e-46) tmp = Float64(Float64(pi / a) / Float64(2.0 * Float64(a * b))); else tmp = Float64(Float64(Float64(Float64(pi / a) / b) * 0.5) / b); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -2e-46)
tmp = (pi / a) / (2.0 * (a * b));
else
tmp = (((pi / a) / b) * 0.5) / b;
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -2e-46], N[(N[(Pi / a), $MachinePrecision] / N[(2.0 * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(Pi / a), $MachinePrecision] / b), $MachinePrecision] * 0.5), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2 \cdot 10^{-46}:\\
\;\;\;\;\frac{\frac{\pi}{a}}{2 \cdot \left(a \cdot b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{\pi}{a}}{b} \cdot 0.5}{b}\\
\end{array}
\end{array}
if a < -2.00000000000000005e-46Initial program 82.0%
associate-*r/82.1%
*-rgt-identity82.1%
associate-*l/82.0%
difference-of-squares89.4%
times-frac99.7%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.6%
expm1-log1p-u87.6%
expm1-udef51.4%
un-div-inv51.4%
+-commutative51.4%
Applied egg-rr51.4%
expm1-def87.6%
expm1-log1p99.6%
associate-/r*97.6%
*-rgt-identity97.6%
times-frac99.6%
associate-/r*99.7%
times-frac99.6%
associate-*l*99.6%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
Taylor expanded in a around inf 84.6%
*-commutative84.6%
Simplified84.6%
if -2.00000000000000005e-46 < a Initial program 77.9%
associate-*r/77.9%
*-rgt-identity77.9%
associate-*l/77.9%
difference-of-squares83.7%
times-frac99.6%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 99.7%
associate-/r*99.6%
Simplified99.6%
Taylor expanded in b around inf 68.9%
*-commutative68.9%
associate-/l/68.9%
*-commutative68.9%
associate-*r/68.9%
*-commutative68.9%
frac-times68.7%
*-un-lft-identity68.7%
associate-/r*68.9%
*-commutative68.9%
*-un-lft-identity68.9%
times-frac68.9%
metadata-eval68.9%
associate-/r*68.9%
Applied egg-rr68.9%
Final simplification73.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -1.9e-46) (/ (/ PI a) (* 2.0 (* a b))) (/ (/ (* 0.5 (/ PI b)) a) b)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -1.9e-46) {
tmp = (((double) M_PI) / a) / (2.0 * (a * b));
} else {
tmp = ((0.5 * (((double) M_PI) / b)) / a) / b;
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -1.9e-46) {
tmp = (Math.PI / a) / (2.0 * (a * b));
} else {
tmp = ((0.5 * (Math.PI / b)) / a) / b;
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -1.9e-46: tmp = (math.pi / a) / (2.0 * (a * b)) else: tmp = ((0.5 * (math.pi / b)) / a) / b return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -1.9e-46) tmp = Float64(Float64(pi / a) / Float64(2.0 * Float64(a * b))); else tmp = Float64(Float64(Float64(0.5 * Float64(pi / b)) / a) / b); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -1.9e-46)
tmp = (pi / a) / (2.0 * (a * b));
else
tmp = ((0.5 * (pi / b)) / a) / b;
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -1.9e-46], N[(N[(Pi / a), $MachinePrecision] / N[(2.0 * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 * N[(Pi / b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.9 \cdot 10^{-46}:\\
\;\;\;\;\frac{\frac{\pi}{a}}{2 \cdot \left(a \cdot b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5 \cdot \frac{\pi}{b}}{a}}{b}\\
\end{array}
\end{array}
if a < -1.8999999999999998e-46Initial program 82.0%
associate-*r/82.1%
*-rgt-identity82.1%
associate-*l/82.0%
difference-of-squares89.4%
times-frac99.7%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.6%
expm1-log1p-u87.6%
expm1-udef51.4%
un-div-inv51.4%
+-commutative51.4%
Applied egg-rr51.4%
expm1-def87.6%
expm1-log1p99.6%
associate-/r*97.6%
*-rgt-identity97.6%
times-frac99.6%
associate-/r*99.7%
times-frac99.6%
associate-*l*99.6%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
Taylor expanded in a around inf 84.6%
*-commutative84.6%
Simplified84.6%
if -1.8999999999999998e-46 < a Initial program 77.9%
associate-*r/77.9%
*-rgt-identity77.9%
associate-*l/77.9%
difference-of-squares83.7%
times-frac99.6%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 99.7%
associate-/r*99.6%
Simplified99.6%
Taylor expanded in b around inf 68.9%
associate-*r/68.9%
un-div-inv69.0%
Applied egg-rr69.0%
Final simplification73.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ PI (* (* a b) (* 2.0 (+ a b)))))
assert(a < b);
double code(double a, double b) {
return ((double) M_PI) / ((a * b) * (2.0 * (a + b)));
}
assert a < b;
public static double code(double a, double b) {
return Math.PI / ((a * b) * (2.0 * (a + b)));
}
[a, b] = sort([a, b]) def code(a, b): return math.pi / ((a * b) * (2.0 * (a + b)))
a, b = sort([a, b]) function code(a, b) return Float64(pi / Float64(Float64(a * b) * Float64(2.0 * Float64(a + b)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = pi / ((a * b) * (2.0 * (a + b)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(Pi / N[(N[(a * b), $MachinePrecision] * N[(2.0 * N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\pi}{\left(a \cdot b\right) \cdot \left(2 \cdot \left(a + b\right)\right)}
\end{array}
Initial program 79.0%
associate-*r/79.0%
*-rgt-identity79.0%
associate-*l/79.0%
difference-of-squares85.2%
times-frac99.7%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.6%
expm1-log1p-u77.6%
expm1-udef48.4%
un-div-inv48.4%
+-commutative48.4%
Applied egg-rr48.4%
expm1-def77.6%
expm1-log1p99.7%
associate-/l/98.7%
*-commutative98.7%
Simplified98.7%
Final simplification98.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ (/ PI (* a b)) (* 2.0 (+ a b))))
assert(a < b);
double code(double a, double b) {
return (((double) M_PI) / (a * b)) / (2.0 * (a + b));
}
assert a < b;
public static double code(double a, double b) {
return (Math.PI / (a * b)) / (2.0 * (a + b));
}
[a, b] = sort([a, b]) def code(a, b): return (math.pi / (a * b)) / (2.0 * (a + b))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(pi / Float64(a * b)) / Float64(2.0 * Float64(a + b))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (pi / (a * b)) / (2.0 * (a + b));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{\pi}{a \cdot b}}{2 \cdot \left(a + b\right)}
\end{array}
Initial program 79.0%
associate-*r/79.0%
*-rgt-identity79.0%
associate-*l/79.0%
difference-of-squares85.2%
times-frac99.7%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
associate-*l/99.6%
add-sqr-sqrt49.0%
sqrt-unprod76.4%
frac-times76.4%
metadata-eval76.4%
metadata-eval76.4%
frac-times76.4%
sqrt-unprod34.8%
add-sqr-sqrt66.0%
*-commutative66.0%
Applied egg-rr66.0%
Taylor expanded in a around 0 99.7%
Final simplification99.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ 0.5 (* b (* a (/ b PI)))))
assert(a < b);
double code(double a, double b) {
return 0.5 / (b * (a * (b / ((double) M_PI))));
}
assert a < b;
public static double code(double a, double b) {
return 0.5 / (b * (a * (b / Math.PI)));
}
[a, b] = sort([a, b]) def code(a, b): return 0.5 / (b * (a * (b / math.pi)))
a, b = sort([a, b]) function code(a, b) return Float64(0.5 / Float64(b * Float64(a * Float64(b / pi)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = 0.5 / (b * (a * (b / pi)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(0.5 / N[(b * N[(a * N[(b / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5}{b \cdot \left(a \cdot \frac{b}{\pi}\right)}
\end{array}
Initial program 79.0%
associate-*r/79.0%
*-rgt-identity79.0%
associate-*l/79.0%
difference-of-squares85.2%
times-frac99.7%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.6%
associate-/r*99.6%
Simplified99.6%
Taylor expanded in b around inf 60.2%
*-commutative60.2%
associate-/l/60.2%
*-commutative60.2%
associate-*r/60.2%
*-commutative60.2%
frac-times60.4%
*-un-lft-identity60.4%
times-frac60.2%
clear-num60.2%
frac-times60.3%
metadata-eval60.3%
*-un-lft-identity60.3%
times-frac60.4%
/-rgt-identity60.4%
Applied egg-rr60.4%
Final simplification60.4%
herbie shell --seed 2023314
(FPCore (a b)
:name "NMSE Section 6.1 mentioned, B"
:precision binary64
(* (* (/ PI 2.0) (/ 1.0 (- (* b b) (* a a)))) (- (/ 1.0 a) (/ 1.0 b))))