
(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 (+ b a))) (* b a)))
double code(double a, double b) {
return (0.5 * (((double) M_PI) / (b + a))) / (b * a);
}
public static double code(double a, double b) {
return (0.5 * (Math.PI / (b + a))) / (b * a);
}
def code(a, b): return (0.5 * (math.pi / (b + a))) / (b * a)
function code(a, b) return Float64(Float64(0.5 * Float64(pi / Float64(b + a))) / Float64(b * a)) end
function tmp = code(a, b) tmp = (0.5 * (pi / (b + a))) / (b * a); end
code[a_, b_] := N[(N[(0.5 * N[(Pi / N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \frac{\pi}{b + a}}{b \cdot a}
\end{array}
Initial program 75.8%
un-div-inv75.8%
difference-of-squares89.9%
associate-/r*90.2%
div-inv90.2%
metadata-eval90.2%
Applied egg-rr90.2%
associate-*l/99.7%
associate-/l*99.7%
Applied egg-rr99.7%
associate-/l*99.6%
associate-*r/99.7%
*-commutative99.7%
+-commutative99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.7%
*-commutative99.7%
Simplified99.7%
un-div-inv99.8%
associate-/l*99.8%
+-commutative99.8%
Applied egg-rr99.8%
(FPCore (a b) :precision binary64 (if (<= b 8.6e-73) (* (* 0.5 (/ PI a)) (/ 1.0 (* b a))) (/ (* 0.5 PI) (* (* b a) (- b a)))))
double code(double a, double b) {
double tmp;
if (b <= 8.6e-73) {
tmp = (0.5 * (((double) M_PI) / a)) * (1.0 / (b * a));
} else {
tmp = (0.5 * ((double) M_PI)) / ((b * a) * (b - a));
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 8.6e-73) {
tmp = (0.5 * (Math.PI / a)) * (1.0 / (b * a));
} else {
tmp = (0.5 * Math.PI) / ((b * a) * (b - a));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 8.6e-73: tmp = (0.5 * (math.pi / a)) * (1.0 / (b * a)) else: tmp = (0.5 * math.pi) / ((b * a) * (b - a)) return tmp
function code(a, b) tmp = 0.0 if (b <= 8.6e-73) tmp = Float64(Float64(0.5 * Float64(pi / a)) * Float64(1.0 / Float64(b * a))); else tmp = Float64(Float64(0.5 * pi) / Float64(Float64(b * a) * Float64(b - a))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 8.6e-73) tmp = (0.5 * (pi / a)) * (1.0 / (b * a)); else tmp = (0.5 * pi) / ((b * a) * (b - a)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 8.6e-73], N[(N[(0.5 * N[(Pi / a), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * Pi), $MachinePrecision] / N[(N[(b * a), $MachinePrecision] * N[(b - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.6 \cdot 10^{-73}:\\
\;\;\;\;\left(0.5 \cdot \frac{\pi}{a}\right) \cdot \frac{1}{b \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot \pi}{\left(b \cdot a\right) \cdot \left(b - a\right)}\\
\end{array}
\end{array}
if b < 8.5999999999999998e-73Initial program 79.5%
un-div-inv79.6%
difference-of-squares92.1%
associate-/r*92.1%
div-inv92.1%
metadata-eval92.1%
Applied egg-rr92.1%
associate-*l/99.7%
associate-/l*99.7%
Applied egg-rr99.7%
associate-/l*99.7%
associate-*r/99.7%
*-commutative99.7%
+-commutative99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.7%
*-commutative99.7%
Simplified99.7%
Taylor expanded in a around inf 72.8%
if 8.5999999999999998e-73 < b Initial program 69.6%
*-commutative69.6%
associate-*r*69.5%
associate-*r/69.5%
associate-*r*69.5%
*-rgt-identity69.5%
sub-neg69.5%
distribute-neg-frac69.5%
metadata-eval69.5%
Simplified69.5%
*-un-lft-identity69.5%
difference-of-squares86.2%
times-frac99.6%
add-sqr-sqrt0.0%
sqrt-unprod93.0%
frac-times93.0%
metadata-eval93.0%
metadata-eval93.0%
frac-times93.0%
sqrt-unprod93.0%
add-sqr-sqrt93.0%
div-inv93.0%
metadata-eval93.0%
Applied egg-rr93.0%
associate-*l/93.1%
*-lft-identity93.1%
associate-/l*93.1%
associate-*l/93.1%
+-commutative93.1%
+-commutative93.1%
*-commutative93.1%
Simplified93.1%
Taylor expanded in b around 0 93.1%
frac-times93.1%
*-un-lft-identity93.1%
Applied egg-rr93.1%
Final simplification80.4%
(FPCore (a b) :precision binary64 (/ (* 0.5 PI) (* (+ b a) (* b a))))
double code(double a, double b) {
return (0.5 * ((double) M_PI)) / ((b + a) * (b * a));
}
public static double code(double a, double b) {
return (0.5 * Math.PI) / ((b + a) * (b * a));
}
def code(a, b): return (0.5 * math.pi) / ((b + a) * (b * a))
function code(a, b) return Float64(Float64(0.5 * pi) / Float64(Float64(b + a) * Float64(b * a))) end
function tmp = code(a, b) tmp = (0.5 * pi) / ((b + a) * (b * a)); end
code[a_, b_] := N[(N[(0.5 * Pi), $MachinePrecision] / N[(N[(b + a), $MachinePrecision] * N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \pi}{\left(b + a\right) \cdot \left(b \cdot a\right)}
\end{array}
Initial program 75.8%
un-div-inv75.8%
difference-of-squares89.9%
associate-/r*90.2%
div-inv90.2%
metadata-eval90.2%
Applied egg-rr90.2%
associate-*l/99.7%
associate-/l*99.7%
Applied egg-rr99.7%
associate-/l*99.6%
associate-*r/99.7%
*-commutative99.7%
+-commutative99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.7%
*-commutative99.7%
Simplified99.7%
*-commutative99.7%
+-commutative99.7%
frac-times99.1%
*-un-lft-identity99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (a b) :precision binary64 (* (* 0.5 (/ PI a)) (/ 1.0 (* b a))))
double code(double a, double b) {
return (0.5 * (((double) M_PI) / a)) * (1.0 / (b * a));
}
public static double code(double a, double b) {
return (0.5 * (Math.PI / a)) * (1.0 / (b * a));
}
def code(a, b): return (0.5 * (math.pi / a)) * (1.0 / (b * a))
function code(a, b) return Float64(Float64(0.5 * Float64(pi / a)) * Float64(1.0 / Float64(b * a))) end
function tmp = code(a, b) tmp = (0.5 * (pi / a)) * (1.0 / (b * a)); end
code[a_, b_] := N[(N[(0.5 * N[(Pi / a), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \frac{\pi}{a}\right) \cdot \frac{1}{b \cdot a}
\end{array}
Initial program 75.8%
un-div-inv75.8%
difference-of-squares89.9%
associate-/r*90.2%
div-inv90.2%
metadata-eval90.2%
Applied egg-rr90.2%
associate-*l/99.7%
associate-/l*99.7%
Applied egg-rr99.7%
associate-/l*99.6%
associate-*r/99.7%
*-commutative99.7%
+-commutative99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.7%
*-commutative99.7%
Simplified99.7%
Taylor expanded in a around inf 65.3%
(FPCore (a b) :precision binary64 (/ (* (/ PI a) -0.5) (* b a)))
double code(double a, double b) {
return ((((double) M_PI) / a) * -0.5) / (b * a);
}
public static double code(double a, double b) {
return ((Math.PI / a) * -0.5) / (b * a);
}
def code(a, b): return ((math.pi / a) * -0.5) / (b * a)
function code(a, b) return Float64(Float64(Float64(pi / a) * -0.5) / Float64(b * a)) end
function tmp = code(a, b) tmp = ((pi / a) * -0.5) / (b * a); end
code[a_, b_] := N[(N[(N[(Pi / a), $MachinePrecision] * -0.5), $MachinePrecision] / N[(b * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\pi}{a} \cdot -0.5}{b \cdot a}
\end{array}
Initial program 75.8%
*-commutative75.8%
associate-*r*75.8%
associate-*r/75.8%
associate-*r*75.8%
*-rgt-identity75.8%
sub-neg75.8%
distribute-neg-frac75.8%
metadata-eval75.8%
Simplified75.8%
*-un-lft-identity75.8%
difference-of-squares89.9%
times-frac99.6%
add-sqr-sqrt46.6%
sqrt-unprod76.8%
frac-times76.8%
metadata-eval76.8%
metadata-eval76.8%
frac-times76.8%
sqrt-unprod38.6%
add-sqr-sqrt69.5%
div-inv69.5%
metadata-eval69.5%
Applied egg-rr69.5%
associate-*l/69.6%
*-lft-identity69.6%
associate-/l*69.6%
associate-*l/69.6%
+-commutative69.6%
+-commutative69.6%
*-commutative69.6%
Simplified69.6%
Taylor expanded in b around 0 69.6%
Taylor expanded in b around 0 36.1%
associate-*l/36.1%
*-un-lft-identity36.1%
*-commutative36.1%
*-commutative36.1%
Applied egg-rr36.1%
herbie shell --seed 2024096
(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))))