
(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 5 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) (/ 0.5 b)) (+ a b)))
assert(a < b);
double code(double a, double b) {
return ((((double) M_PI) / a) * (0.5 / b)) / (a + b);
}
assert a < b;
public static double code(double a, double b) {
return ((Math.PI / a) * (0.5 / b)) / (a + b);
}
[a, b] = sort([a, b]) def code(a, b): return ((math.pi / a) * (0.5 / b)) / (a + b)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(Float64(pi / a) * Float64(0.5 / b)) / Float64(a + b)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = ((pi / a) * (0.5 / b)) / (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] * N[(0.5 / b), $MachinePrecision]), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{\pi}{a} \cdot \frac{0.5}{b}}{a + b}
\end{array}
Initial program 74.0%
*-commutative74.0%
associate-*r*73.9%
associate-*r/74.0%
associate-*r*74.0%
*-rgt-identity74.0%
sub-neg74.0%
distribute-neg-frac74.0%
metadata-eval74.0%
Simplified74.0%
*-commutative74.0%
difference-of-squares84.1%
times-frac99.6%
div-inv99.6%
metadata-eval99.6%
add-sqr-sqrt44.7%
sqrt-unprod71.3%
frac-times71.3%
metadata-eval71.3%
metadata-eval71.3%
frac-times71.3%
sqrt-unprod33.9%
add-sqr-sqrt65.2%
Applied egg-rr65.2%
associate-*l/65.2%
*-commutative65.2%
+-commutative65.2%
+-commutative65.2%
Simplified65.2%
Taylor expanded in b around inf 61.5%
distribute-lft-out61.5%
neg-mul-161.5%
sub-neg61.5%
remove-double-neg61.5%
Simplified61.5%
Taylor expanded in a around 0 99.7%
*-commutative99.7%
associate-*l/99.7%
times-frac99.7%
Simplified99.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -1.15e+154) (* 0.5 (/ PI (* (+ a b) (* a b)))) (* 0.5 (/ (/ PI b) (* a (+ a b))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -1.15e+154) {
tmp = 0.5 * (((double) M_PI) / ((a + b) * (a * b)));
} else {
tmp = 0.5 * ((((double) M_PI) / b) / (a * (a + b)));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -1.15e+154) {
tmp = 0.5 * (Math.PI / ((a + b) * (a * b)));
} else {
tmp = 0.5 * ((Math.PI / b) / (a * (a + b)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -1.15e+154: tmp = 0.5 * (math.pi / ((a + b) * (a * b))) else: tmp = 0.5 * ((math.pi / b) / (a * (a + b))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -1.15e+154) tmp = Float64(0.5 * Float64(pi / Float64(Float64(a + b) * Float64(a * b)))); else tmp = Float64(0.5 * Float64(Float64(pi / b) / Float64(a * Float64(a + b)))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -1.15e+154)
tmp = 0.5 * (pi / ((a + b) * (a * b)));
else
tmp = 0.5 * ((pi / b) / (a * (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.15e+154], N[(0.5 * N[(Pi / N[(N[(a + b), $MachinePrecision] * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(Pi / b), $MachinePrecision] / N[(a * N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.15 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \frac{\pi}{\left(a + b\right) \cdot \left(a \cdot b\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{\frac{\pi}{b}}{a \cdot \left(a + b\right)}\\
\end{array}
\end{array}
if a < -1.15e154Initial program 51.5%
*-commutative51.5%
associate-*r*51.5%
associate-*r/51.5%
associate-*r*51.5%
*-rgt-identity51.5%
sub-neg51.5%
distribute-neg-frac51.5%
metadata-eval51.5%
Simplified51.5%
*-commutative51.5%
difference-of-squares67.8%
times-frac99.7%
div-inv99.7%
metadata-eval99.7%
add-sqr-sqrt44.1%
sqrt-unprod68.1%
frac-times68.1%
metadata-eval68.1%
metadata-eval68.1%
frac-times68.1%
sqrt-unprod35.9%
add-sqr-sqrt67.3%
Applied egg-rr67.3%
associate-*l/67.3%
*-commutative67.3%
+-commutative67.3%
+-commutative67.3%
Simplified67.3%
Taylor expanded in b around inf 99.9%
associate-/l*99.9%
Applied egg-rr99.9%
associate-/l/98.2%
Simplified98.2%
if -1.15e154 < a Initial program 78.5%
*-commutative78.5%
associate-*r*78.4%
associate-*r/78.5%
associate-*r*78.5%
*-rgt-identity78.5%
sub-neg78.5%
distribute-neg-frac78.5%
metadata-eval78.5%
Simplified78.5%
*-commutative78.5%
difference-of-squares87.4%
times-frac99.6%
div-inv99.6%
metadata-eval99.6%
add-sqr-sqrt44.9%
sqrt-unprod71.9%
frac-times71.9%
metadata-eval71.9%
metadata-eval71.9%
frac-times71.9%
sqrt-unprod33.5%
add-sqr-sqrt64.8%
Applied egg-rr64.8%
associate-*l/64.8%
*-commutative64.8%
+-commutative64.8%
+-commutative64.8%
Simplified64.8%
Taylor expanded in b around inf 99.7%
associate-/l*99.7%
Applied egg-rr99.7%
associate-/l/97.7%
Simplified97.7%
*-un-lft-identity97.7%
associate-*r*94.0%
times-frac95.5%
Applied egg-rr95.5%
associate-*l/95.6%
*-lft-identity95.6%
*-commutative95.6%
Simplified95.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ (* 0.5 (/ PI (* a b))) (+ a b)))
assert(a < b);
double code(double a, double b) {
return (0.5 * (((double) M_PI) / (a * b))) / (a + b);
}
assert a < b;
public static double code(double a, double b) {
return (0.5 * (Math.PI / (a * b))) / (a + b);
}
[a, b] = sort([a, b]) def code(a, b): return (0.5 * (math.pi / (a * b))) / (a + b)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(0.5 * Float64(pi / Float64(a * b))) / Float64(a + b)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (0.5 * (pi / (a * b))) / (a + b);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(0.5 * N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5 \cdot \frac{\pi}{a \cdot b}}{a + b}
\end{array}
Initial program 74.0%
*-commutative74.0%
associate-*r*73.9%
associate-*r/74.0%
associate-*r*74.0%
*-rgt-identity74.0%
sub-neg74.0%
distribute-neg-frac74.0%
metadata-eval74.0%
Simplified74.0%
*-commutative74.0%
difference-of-squares84.1%
times-frac99.6%
div-inv99.6%
metadata-eval99.6%
add-sqr-sqrt44.7%
sqrt-unprod71.3%
frac-times71.3%
metadata-eval71.3%
metadata-eval71.3%
frac-times71.3%
sqrt-unprod33.9%
add-sqr-sqrt65.2%
Applied egg-rr65.2%
associate-*l/65.2%
*-commutative65.2%
+-commutative65.2%
+-commutative65.2%
Simplified65.2%
Taylor expanded in b around inf 99.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* PI (/ (/ 0.5 (+ a b)) (* a b))))
assert(a < b);
double code(double a, double b) {
return ((double) M_PI) * ((0.5 / (a + b)) / (a * b));
}
assert a < b;
public static double code(double a, double b) {
return Math.PI * ((0.5 / (a + b)) / (a * b));
}
[a, b] = sort([a, b]) def code(a, b): return math.pi * ((0.5 / (a + b)) / (a * b))
a, b = sort([a, b]) function code(a, b) return Float64(pi * Float64(Float64(0.5 / Float64(a + b)) / Float64(a * b))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = pi * ((0.5 / (a + b)) / (a * b));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(Pi * N[(N[(0.5 / N[(a + b), $MachinePrecision]), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\pi \cdot \frac{\frac{0.5}{a + b}}{a \cdot b}
\end{array}
Initial program 74.0%
*-commutative74.0%
associate-*r*73.9%
associate-*r/74.0%
associate-*r*74.0%
*-rgt-identity74.0%
sub-neg74.0%
distribute-neg-frac74.0%
metadata-eval74.0%
Simplified74.0%
*-commutative74.0%
difference-of-squares84.1%
times-frac99.6%
div-inv99.6%
metadata-eval99.6%
add-sqr-sqrt44.7%
sqrt-unprod71.3%
frac-times71.3%
metadata-eval71.3%
metadata-eval71.3%
frac-times71.3%
sqrt-unprod33.9%
add-sqr-sqrt65.2%
Applied egg-rr65.2%
associate-*l/65.2%
*-commutative65.2%
+-commutative65.2%
+-commutative65.2%
Simplified65.2%
Taylor expanded in b around inf 61.5%
distribute-lft-out61.5%
neg-mul-161.5%
sub-neg61.5%
remove-double-neg61.5%
Simplified61.5%
Taylor expanded in a around 0 99.7%
*-commutative99.7%
associate-*l/99.7%
times-frac99.7%
Simplified99.7%
div-inv99.6%
frac-times99.7%
associate-*l/99.7%
associate-*l*99.7%
div-inv99.7%
div-inv99.6%
associate-*l*99.6%
Applied egg-rr99.6%
associate-*l/99.6%
*-lft-identity99.6%
Simplified99.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* 0.5 (/ PI (* (+ a b) (* a b)))))
assert(a < b);
double code(double a, double b) {
return 0.5 * (((double) M_PI) / ((a + b) * (a * b)));
}
assert a < b;
public static double code(double a, double b) {
return 0.5 * (Math.PI / ((a + b) * (a * b)));
}
[a, b] = sort([a, b]) def code(a, b): return 0.5 * (math.pi / ((a + b) * (a * b)))
a, b = sort([a, b]) function code(a, b) return Float64(0.5 * Float64(pi / Float64(Float64(a + b) * Float64(a * b)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = 0.5 * (pi / ((a + b) * (a * b)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(0.5 * N[(Pi / N[(N[(a + b), $MachinePrecision] * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
0.5 \cdot \frac{\pi}{\left(a + b\right) \cdot \left(a \cdot b\right)}
\end{array}
Initial program 74.0%
*-commutative74.0%
associate-*r*73.9%
associate-*r/74.0%
associate-*r*74.0%
*-rgt-identity74.0%
sub-neg74.0%
distribute-neg-frac74.0%
metadata-eval74.0%
Simplified74.0%
*-commutative74.0%
difference-of-squares84.1%
times-frac99.6%
div-inv99.6%
metadata-eval99.6%
add-sqr-sqrt44.7%
sqrt-unprod71.3%
frac-times71.3%
metadata-eval71.3%
metadata-eval71.3%
frac-times71.3%
sqrt-unprod33.9%
add-sqr-sqrt65.2%
Applied egg-rr65.2%
associate-*l/65.2%
*-commutative65.2%
+-commutative65.2%
+-commutative65.2%
Simplified65.2%
Taylor expanded in b around inf 99.7%
associate-/l*99.7%
Applied egg-rr99.7%
associate-/l/97.8%
Simplified97.8%
herbie shell --seed 2024084
(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))))