
(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}
(FPCore (a b) :precision binary64 (/ (/ (* 0.5 PI) (* a b)) (+ a b)))
double code(double a, double b) {
return ((0.5 * ((double) M_PI)) / (a * b)) / (a + b);
}
public static double code(double a, double b) {
return ((0.5 * Math.PI) / (a * b)) / (a + b);
}
def code(a, b): return ((0.5 * math.pi) / (a * b)) / (a + b)
function code(a, b) return Float64(Float64(Float64(0.5 * pi) / Float64(a * b)) / Float64(a + b)) end
function tmp = code(a, b) tmp = ((0.5 * pi) / (a * b)) / (a + b); end
code[a_, b_] := N[(N[(N[(0.5 * Pi), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{0.5 \cdot \pi}{a \cdot b}}{a + b}
\end{array}
Initial program 74.2%
*-commutative74.2%
associate-*r*74.2%
associate-*r/74.2%
associate-*r*74.2%
*-rgt-identity74.2%
sub-neg74.2%
distribute-neg-frac74.2%
metadata-eval74.2%
Simplified74.2%
*-un-lft-identity74.2%
difference-of-squares82.0%
times-frac99.5%
add-sqr-sqrt51.3%
sqrt-unprod73.0%
frac-times73.0%
metadata-eval73.0%
metadata-eval73.0%
frac-times73.0%
sqrt-unprod34.2%
add-sqr-sqrt63.4%
div-inv63.4%
metadata-eval63.4%
Applied egg-rr63.4%
associate-*l/63.5%
associate-/l*63.5%
+-commutative63.5%
*-commutative63.5%
+-commutative63.5%
Simplified63.5%
Taylor expanded in b around inf 99.7%
associate-*r/99.7%
Simplified99.7%
*-un-lft-identity99.7%
Applied egg-rr99.7%
(FPCore (a b) :precision binary64 (if (<= b 6e+39) (* (/ 0.5 a) (/ (/ PI b) (+ a b))) (* (/ 0.5 b) (/ (/ PI (+ a b)) a))))
double code(double a, double b) {
double tmp;
if (b <= 6e+39) {
tmp = (0.5 / a) * ((((double) M_PI) / b) / (a + b));
} else {
tmp = (0.5 / b) * ((((double) M_PI) / (a + b)) / a);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 6e+39) {
tmp = (0.5 / a) * ((Math.PI / b) / (a + b));
} else {
tmp = (0.5 / b) * ((Math.PI / (a + b)) / a);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 6e+39: tmp = (0.5 / a) * ((math.pi / b) / (a + b)) else: tmp = (0.5 / b) * ((math.pi / (a + b)) / a) return tmp
function code(a, b) tmp = 0.0 if (b <= 6e+39) tmp = Float64(Float64(0.5 / a) * Float64(Float64(pi / b) / Float64(a + b))); else tmp = Float64(Float64(0.5 / b) * Float64(Float64(pi / Float64(a + b)) / a)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 6e+39) tmp = (0.5 / a) * ((pi / b) / (a + b)); else tmp = (0.5 / b) * ((pi / (a + b)) / a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 6e+39], N[(N[(0.5 / a), $MachinePrecision] * N[(N[(Pi / b), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / b), $MachinePrecision] * N[(N[(Pi / N[(a + b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6 \cdot 10^{+39}:\\
\;\;\;\;\frac{0.5}{a} \cdot \frac{\frac{\pi}{b}}{a + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{b} \cdot \frac{\frac{\pi}{a + b}}{a}\\
\end{array}
\end{array}
if b < 5.9999999999999999e39Initial program 79.7%
*-commutative79.7%
associate-*r*79.7%
associate-*r/79.7%
associate-*r*79.7%
*-rgt-identity79.7%
sub-neg79.7%
distribute-neg-frac79.7%
metadata-eval79.7%
Simplified79.7%
*-un-lft-identity79.7%
difference-of-squares84.7%
times-frac99.5%
add-sqr-sqrt66.0%
sqrt-unprod65.5%
frac-times65.5%
metadata-eval65.5%
metadata-eval65.5%
frac-times65.5%
sqrt-unprod15.6%
add-sqr-sqrt53.3%
div-inv53.3%
metadata-eval53.3%
Applied egg-rr53.3%
associate-*l/53.3%
associate-/l*53.3%
+-commutative53.3%
*-commutative53.3%
+-commutative53.3%
Simplified53.3%
Taylor expanded in b around inf 99.7%
associate-*r/99.7%
Simplified99.7%
*-un-lft-identity99.7%
Applied egg-rr99.7%
times-frac99.6%
associate-/l*95.3%
Applied egg-rr95.3%
if 5.9999999999999999e39 < b Initial program 55.2%
*-commutative55.2%
associate-*r*55.2%
associate-*r/55.2%
associate-*r*55.2%
*-rgt-identity55.2%
sub-neg55.2%
distribute-neg-frac55.2%
metadata-eval55.2%
Simplified55.2%
*-un-lft-identity55.2%
difference-of-squares72.7%
times-frac99.7%
add-sqr-sqrt0.0%
sqrt-unprod99.0%
frac-times99.0%
metadata-eval99.0%
metadata-eval99.0%
frac-times99.0%
sqrt-unprod99.0%
add-sqr-sqrt99.0%
div-inv99.0%
metadata-eval99.0%
Applied egg-rr99.0%
associate-*l/99.0%
associate-/l*98.9%
+-commutative98.9%
*-commutative98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in b around inf 99.8%
associate-*r/99.8%
Simplified99.8%
*-un-lft-identity99.8%
Applied egg-rr99.8%
associate-/l/98.9%
associate-/r*99.7%
associate-/l*99.7%
*-commutative99.7%
times-frac99.6%
Applied egg-rr99.6%
(FPCore (a b) :precision binary64 (* (/ PI (+ a b)) (/ 0.5 (* a b))))
double code(double a, double b) {
return (((double) M_PI) / (a + b)) * (0.5 / (a * b));
}
public static double code(double a, double b) {
return (Math.PI / (a + b)) * (0.5 / (a * b));
}
def code(a, b): return (math.pi / (a + b)) * (0.5 / (a * b))
function code(a, b) return Float64(Float64(pi / Float64(a + b)) * Float64(0.5 / Float64(a * b))) end
function tmp = code(a, b) tmp = (pi / (a + b)) * (0.5 / (a * b)); end
code[a_, b_] := N[(N[(Pi / N[(a + b), $MachinePrecision]), $MachinePrecision] * N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{a + b} \cdot \frac{0.5}{a \cdot b}
\end{array}
Initial program 74.2%
*-commutative74.2%
associate-*r*74.2%
associate-*r/74.2%
associate-*r*74.2%
*-rgt-identity74.2%
sub-neg74.2%
distribute-neg-frac74.2%
metadata-eval74.2%
Simplified74.2%
*-un-lft-identity74.2%
difference-of-squares82.0%
times-frac99.5%
add-sqr-sqrt51.3%
sqrt-unprod73.0%
frac-times73.0%
metadata-eval73.0%
metadata-eval73.0%
frac-times73.0%
sqrt-unprod34.2%
add-sqr-sqrt63.4%
div-inv63.4%
metadata-eval63.4%
Applied egg-rr63.4%
associate-*l/63.5%
associate-/l*63.5%
+-commutative63.5%
*-commutative63.5%
+-commutative63.5%
Simplified63.5%
Taylor expanded in b around inf 99.7%
associate-*r/99.7%
Simplified99.7%
*-un-lft-identity99.7%
Applied egg-rr99.7%
associate-/l/99.2%
*-commutative99.2%
times-frac99.7%
Applied egg-rr99.7%
(FPCore (a b) :precision binary64 (* (/ 0.5 a) (/ (/ PI b) (+ a b))))
double code(double a, double b) {
return (0.5 / a) * ((((double) M_PI) / b) / (a + b));
}
public static double code(double a, double b) {
return (0.5 / a) * ((Math.PI / b) / (a + b));
}
def code(a, b): return (0.5 / a) * ((math.pi / b) / (a + b))
function code(a, b) return Float64(Float64(0.5 / a) * Float64(Float64(pi / b) / Float64(a + b))) end
function tmp = code(a, b) tmp = (0.5 / a) * ((pi / b) / (a + b)); end
code[a_, b_] := N[(N[(0.5 / a), $MachinePrecision] * N[(N[(Pi / b), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{a} \cdot \frac{\frac{\pi}{b}}{a + b}
\end{array}
Initial program 74.2%
*-commutative74.2%
associate-*r*74.2%
associate-*r/74.2%
associate-*r*74.2%
*-rgt-identity74.2%
sub-neg74.2%
distribute-neg-frac74.2%
metadata-eval74.2%
Simplified74.2%
*-un-lft-identity74.2%
difference-of-squares82.0%
times-frac99.5%
add-sqr-sqrt51.3%
sqrt-unprod73.0%
frac-times73.0%
metadata-eval73.0%
metadata-eval73.0%
frac-times73.0%
sqrt-unprod34.2%
add-sqr-sqrt63.4%
div-inv63.4%
metadata-eval63.4%
Applied egg-rr63.4%
associate-*l/63.5%
associate-/l*63.5%
+-commutative63.5%
*-commutative63.5%
+-commutative63.5%
Simplified63.5%
Taylor expanded in b around inf 99.7%
associate-*r/99.7%
Simplified99.7%
*-un-lft-identity99.7%
Applied egg-rr99.7%
times-frac99.6%
associate-/l*90.9%
Applied egg-rr90.9%
(FPCore (a b) :precision binary64 (/ (* 0.5 (/ PI a)) (* a b)))
double code(double a, double b) {
return (0.5 * (((double) M_PI) / a)) / (a * b);
}
public static double code(double a, double b) {
return (0.5 * (Math.PI / a)) / (a * b);
}
def code(a, b): return (0.5 * (math.pi / a)) / (a * b)
function code(a, b) return Float64(Float64(0.5 * Float64(pi / a)) / Float64(a * b)) end
function tmp = code(a, b) tmp = (0.5 * (pi / a)) / (a * b); end
code[a_, b_] := N[(N[(0.5 * N[(Pi / a), $MachinePrecision]), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \frac{\pi}{a}}{a \cdot b}
\end{array}
Initial program 74.2%
*-commutative74.2%
associate-*r*74.2%
associate-*r/74.2%
associate-*r*74.2%
*-rgt-identity74.2%
sub-neg74.2%
distribute-neg-frac74.2%
metadata-eval74.2%
Simplified74.2%
*-un-lft-identity74.2%
difference-of-squares82.0%
times-frac99.5%
add-sqr-sqrt51.3%
sqrt-unprod73.0%
frac-times73.0%
metadata-eval73.0%
metadata-eval73.0%
frac-times73.0%
sqrt-unprod34.2%
add-sqr-sqrt63.4%
div-inv63.4%
metadata-eval63.4%
Applied egg-rr63.4%
associate-*l/63.5%
associate-/l*63.5%
+-commutative63.5%
*-commutative63.5%
+-commutative63.5%
Simplified63.5%
Taylor expanded in b around inf 99.7%
associate-*r/99.7%
Simplified99.7%
*-un-lft-identity99.7%
*-un-lft-identity99.7%
associate-/r*99.7%
Applied egg-rr99.7%
*-lft-identity99.7%
associate-/l/90.1%
associate-*r/90.1%
Simplified90.1%
Taylor expanded in a around inf 64.8%
herbie shell --seed 2024137
(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))))