
(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 b) (* 2.0 a)) (+ b a)))
assert(a < b);
double code(double a, double b) {
return ((((double) M_PI) / b) / (2.0 * a)) / (b + a);
}
assert a < b;
public static double code(double a, double b) {
return ((Math.PI / b) / (2.0 * a)) / (b + a);
}
[a, b] = sort([a, b]) def code(a, b): return ((math.pi / b) / (2.0 * a)) / (b + a)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(Float64(pi / b) / Float64(2.0 * a)) / Float64(b + a)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = ((pi / b) / (2.0 * a)) / (b + a);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(N[(Pi / b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{\frac{\pi}{b}}{2 \cdot a}}{b + a}
\end{array}
Initial program 80.2%
associate-*l*80.2%
associate-*l/80.2%
*-lft-identity80.2%
difference-of-squares90.4%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.6%
associate-/r*99.7%
metadata-eval99.7%
distribute-neg-frac99.7%
distribute-neg-frac99.7%
*-lft-identity99.7%
associate-*l/99.7%
distribute-lft-neg-in99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
metadata-eval99.7%
distribute-neg-frac99.7%
distribute-rgt-neg-in99.7%
*-commutative99.7%
associate-*l/99.7%
*-lft-identity99.7%
distribute-neg-frac99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
metadata-eval99.7%
div-inv99.7%
frac-times99.7%
div-inv99.7%
Applied egg-rr99.7%
Final simplification99.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* PI (/ 0.5 (* (+ b a) (* b a)))))
assert(a < b);
double code(double a, double b) {
return ((double) M_PI) * (0.5 / ((b + a) * (b * a)));
}
assert a < b;
public static double code(double a, double b) {
return Math.PI * (0.5 / ((b + a) * (b * a)));
}
[a, b] = sort([a, b]) def code(a, b): return math.pi * (0.5 / ((b + a) * (b * a)))
a, b = sort([a, b]) function code(a, b) return Float64(pi * Float64(0.5 / Float64(Float64(b + a) * Float64(b * a)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = pi * (0.5 / ((b + a) * (b * a)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(Pi * N[(0.5 / N[(N[(b + a), $MachinePrecision] * N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\pi \cdot \frac{0.5}{\left(b + a\right) \cdot \left(b \cdot a\right)}
\end{array}
Initial program 80.2%
associate-*l*80.2%
associate-*l/80.2%
*-lft-identity80.2%
difference-of-squares90.4%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.6%
associate-/r*99.7%
metadata-eval99.7%
distribute-neg-frac99.7%
distribute-neg-frac99.7%
*-lft-identity99.7%
associate-*l/99.7%
distribute-lft-neg-in99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
metadata-eval99.7%
distribute-neg-frac99.7%
distribute-rgt-neg-in99.7%
*-commutative99.7%
associate-*l/99.7%
*-lft-identity99.7%
distribute-neg-frac99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
metadata-eval99.7%
div-inv99.7%
frac-times99.7%
div-inv99.7%
Applied egg-rr99.7%
expm1-log1p-u80.1%
expm1-udef57.8%
associate-/l/57.8%
Applied egg-rr57.8%
expm1-def74.6%
expm1-log1p94.2%
*-lft-identity94.2%
associate-*l/94.2%
associate-/l/95.0%
*-commutative95.0%
associate-*r/99.7%
associate-/r*99.7%
metadata-eval99.7%
times-frac99.7%
associate-/r*99.7%
associate-*r/99.7%
associate-/r*94.2%
times-frac95.9%
associate-/r*95.9%
associate-*l/95.8%
associate-*r/95.8%
associate-/l/95.4%
remove-double-neg95.4%
Simplified99.0%
Final simplification99.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ 0.5 (* (+ b a) (* b (/ a PI)))))
assert(a < b);
double code(double a, double b) {
return 0.5 / ((b + a) * (b * (a / ((double) M_PI))));
}
assert a < b;
public static double code(double a, double b) {
return 0.5 / ((b + a) * (b * (a / Math.PI)));
}
[a, b] = sort([a, b]) def code(a, b): return 0.5 / ((b + a) * (b * (a / math.pi)))
a, b = sort([a, b]) function code(a, b) return Float64(0.5 / Float64(Float64(b + a) * Float64(b * Float64(a / pi)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = 0.5 / ((b + a) * (b * (a / pi)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(0.5 / N[(N[(b + a), $MachinePrecision] * N[(b * N[(a / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5}{\left(b + a\right) \cdot \left(b \cdot \frac{a}{\pi}\right)}
\end{array}
Initial program 80.2%
associate-*l*80.2%
associate-*l/80.2%
*-lft-identity80.2%
difference-of-squares90.4%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 99.6%
associate-/r*99.7%
metadata-eval99.7%
distribute-neg-frac99.7%
distribute-neg-frac99.7%
*-lft-identity99.7%
associate-*l/99.7%
distribute-lft-neg-in99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
metadata-eval99.7%
distribute-neg-frac99.7%
distribute-rgt-neg-in99.7%
*-commutative99.7%
associate-*l/99.7%
*-lft-identity99.7%
distribute-neg-frac99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.6%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
*-commutative99.7%
associate-/l/99.6%
div-inv99.7%
div-inv99.6%
associate-/l*99.5%
frac-times99.0%
metadata-eval99.0%
*-commutative99.0%
*-un-lft-identity99.0%
times-frac99.0%
/-rgt-identity99.0%
Applied egg-rr99.0%
Final simplification99.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ (* (/ PI a) (/ 0.5 b)) (+ b a)))
assert(a < b);
double code(double a, double b) {
return ((((double) M_PI) / a) * (0.5 / b)) / (b + a);
}
assert a < b;
public static double code(double a, double b) {
return ((Math.PI / a) * (0.5 / b)) / (b + a);
}
[a, b] = sort([a, b]) def code(a, b): return ((math.pi / a) * (0.5 / b)) / (b + a)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(Float64(pi / a) * Float64(0.5 / b)) / Float64(b + a)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = ((pi / a) * (0.5 / b)) / (b + a);
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[(b + a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{\pi}{a} \cdot \frac{0.5}{b}}{b + a}
\end{array}
Initial program 80.2%
associate-*l*80.2%
associate-*l/80.2%
*-lft-identity80.2%
difference-of-squares90.4%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.7%
associate-*r/99.7%
Simplified99.7%
*-commutative99.7%
times-frac99.7%
Applied egg-rr99.7%
Final simplification99.7%
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))))
assert(a < b);
double code(double a, double b) {
return (((double) M_PI) / a) * (0.5 / (b * a));
}
assert a < b;
public static double code(double a, double b) {
return (Math.PI / a) * (0.5 / (b * a));
}
[a, b] = sort([a, b]) def code(a, b): return (math.pi / a) * (0.5 / (b * a))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(pi / a) * Float64(0.5 / Float64(b * a))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (pi / a) * (0.5 / (b * a));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(Pi / a), $MachinePrecision] * N[(0.5 / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\pi}{a} \cdot \frac{0.5}{b \cdot a}
\end{array}
Initial program 80.2%
associate-*l*80.2%
associate-*l/80.2%
*-lft-identity80.2%
difference-of-squares90.4%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.6%
associate-/r*99.7%
metadata-eval99.7%
distribute-neg-frac99.7%
distribute-neg-frac99.7%
*-lft-identity99.7%
associate-*l/99.7%
distribute-lft-neg-in99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
metadata-eval99.7%
distribute-neg-frac99.7%
distribute-rgt-neg-in99.7%
*-commutative99.7%
associate-*l/99.7%
*-lft-identity99.7%
distribute-neg-frac99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
metadata-eval99.7%
div-inv99.7%
associate-*r/99.6%
div-inv99.5%
associate-/l/99.6%
frac-times99.0%
metadata-eval99.0%
+-commutative99.0%
associate-*r*95.4%
div-inv95.4%
div-inv95.4%
metadata-eval95.4%
times-frac95.9%
+-commutative95.9%
Applied egg-rr95.9%
Taylor expanded in b around 0 64.8%
Final simplification64.8%
herbie shell --seed 2024019
(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))))