
(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 7 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 (* (/ 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 77.6%
associate-*l*77.5%
*-rgt-identity77.5%
associate-/l*77.5%
metadata-eval77.5%
associate-*l/77.6%
*-lft-identity77.6%
sub-neg77.6%
distribute-neg-frac77.6%
metadata-eval77.6%
Simplified77.6%
metadata-eval77.6%
div-inv77.6%
*-commutative77.6%
clear-num77.6%
frac-times77.6%
*-un-lft-identity77.6%
frac-add77.5%
associate-/r/77.6%
*-un-lft-identity77.6%
*-commutative77.6%
neg-mul-177.6%
sub-neg77.6%
flip-+99.0%
+-commutative99.0%
Applied egg-rr99.0%
*-commutative99.0%
associate-/r*99.0%
Simplified99.0%
div-inv99.0%
metadata-eval99.0%
times-frac99.7%
Applied egg-rr99.7%
(FPCore (a b) :precision binary64 (if (<= b 8.5e-10) (* PI (/ (/ 0.5 a) (* a b))) (* (/ 0.5 (* a b)) (/ PI b))))
double code(double a, double b) {
double tmp;
if (b <= 8.5e-10) {
tmp = ((double) M_PI) * ((0.5 / a) / (a * b));
} else {
tmp = (0.5 / (a * b)) * (((double) M_PI) / b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 8.5e-10) {
tmp = Math.PI * ((0.5 / a) / (a * b));
} else {
tmp = (0.5 / (a * b)) * (Math.PI / b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 8.5e-10: tmp = math.pi * ((0.5 / a) / (a * b)) else: tmp = (0.5 / (a * b)) * (math.pi / b) return tmp
function code(a, b) tmp = 0.0 if (b <= 8.5e-10) tmp = Float64(pi * Float64(Float64(0.5 / a) / Float64(a * b))); else tmp = Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 8.5e-10) tmp = pi * ((0.5 / a) / (a * b)); else tmp = (0.5 / (a * b)) * (pi / b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 8.5e-10], N[(Pi * N[(N[(0.5 / a), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.5 \cdot 10^{-10}:\\
\;\;\;\;\pi \cdot \frac{\frac{0.5}{a}}{a \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a \cdot b} \cdot \frac{\pi}{b}\\
\end{array}
\end{array}
if b < 8.4999999999999996e-10Initial program 76.8%
*-commutative76.8%
associate-*r*76.7%
associate-*r/76.7%
associate-*r*76.7%
*-rgt-identity76.7%
sub-neg76.7%
distribute-neg-frac76.7%
metadata-eval76.7%
Simplified76.7%
*-commutative76.7%
associate-*r/76.8%
div-inv76.8%
metadata-eval76.8%
associate-*l*76.8%
*-commutative76.8%
Applied egg-rr99.4%
Taylor expanded in a around inf 72.7%
associate-/r*73.0%
div-inv73.1%
Applied egg-rr73.1%
associate-*r/73.0%
*-rgt-identity73.0%
Simplified73.0%
if 8.4999999999999996e-10 < b Initial program 79.9%
associate-*l*79.8%
*-rgt-identity79.8%
associate-/l*79.8%
metadata-eval79.8%
associate-*l/79.9%
*-lft-identity79.9%
sub-neg79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
Simplified79.9%
metadata-eval79.9%
div-inv79.9%
*-commutative79.9%
clear-num79.8%
frac-times79.9%
*-un-lft-identity79.9%
frac-add79.9%
associate-/r/79.9%
*-un-lft-identity79.9%
*-commutative79.9%
neg-mul-179.9%
sub-neg79.9%
flip-+97.7%
+-commutative97.7%
Applied egg-rr97.7%
*-commutative97.7%
associate-/r*97.7%
Simplified97.7%
div-inv97.7%
metadata-eval97.7%
times-frac99.8%
Applied egg-rr99.8%
Taylor expanded in a around 0 95.5%
Final simplification78.8%
(FPCore (a b) :precision binary64 (let* ((t_0 (/ 0.5 (* a b)))) (if (<= b 1.72e-12) (* t_0 (/ PI a)) (* t_0 (/ PI b)))))
double code(double a, double b) {
double t_0 = 0.5 / (a * b);
double tmp;
if (b <= 1.72e-12) {
tmp = t_0 * (((double) M_PI) / a);
} else {
tmp = t_0 * (((double) M_PI) / b);
}
return tmp;
}
public static double code(double a, double b) {
double t_0 = 0.5 / (a * b);
double tmp;
if (b <= 1.72e-12) {
tmp = t_0 * (Math.PI / a);
} else {
tmp = t_0 * (Math.PI / b);
}
return tmp;
}
def code(a, b): t_0 = 0.5 / (a * b) tmp = 0 if b <= 1.72e-12: tmp = t_0 * (math.pi / a) else: tmp = t_0 * (math.pi / b) return tmp
function code(a, b) t_0 = Float64(0.5 / Float64(a * b)) tmp = 0.0 if (b <= 1.72e-12) tmp = Float64(t_0 * Float64(pi / a)); else tmp = Float64(t_0 * Float64(pi / b)); end return tmp end
function tmp_2 = code(a, b) t_0 = 0.5 / (a * b); tmp = 0.0; if (b <= 1.72e-12) tmp = t_0 * (pi / a); else tmp = t_0 * (pi / b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.72e-12], N[(t$95$0 * N[(Pi / a), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(Pi / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{0.5}{a \cdot b}\\
\mathbf{if}\;b \leq 1.72 \cdot 10^{-12}:\\
\;\;\;\;t\_0 \cdot \frac{\pi}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \frac{\pi}{b}\\
\end{array}
\end{array}
if b < 1.7199999999999999e-12Initial program 76.8%
associate-*l*76.7%
*-rgt-identity76.7%
associate-/l*76.7%
metadata-eval76.7%
associate-*l/76.8%
*-lft-identity76.8%
sub-neg76.8%
distribute-neg-frac76.8%
metadata-eval76.8%
Simplified76.8%
metadata-eval76.8%
div-inv76.8%
*-commutative76.8%
clear-num76.8%
frac-times76.8%
*-un-lft-identity76.8%
frac-add76.7%
associate-/r/76.8%
*-un-lft-identity76.8%
*-commutative76.8%
neg-mul-176.8%
sub-neg76.8%
flip-+99.4%
+-commutative99.4%
Applied egg-rr99.4%
*-commutative99.4%
associate-/r*99.4%
Simplified99.4%
div-inv99.4%
metadata-eval99.4%
times-frac99.6%
Applied egg-rr99.6%
Taylor expanded in a around inf 73.0%
if 1.7199999999999999e-12 < b Initial program 79.9%
associate-*l*79.8%
*-rgt-identity79.8%
associate-/l*79.8%
metadata-eval79.8%
associate-*l/79.9%
*-lft-identity79.9%
sub-neg79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
Simplified79.9%
metadata-eval79.9%
div-inv79.9%
*-commutative79.9%
clear-num79.8%
frac-times79.9%
*-un-lft-identity79.9%
frac-add79.9%
associate-/r/79.9%
*-un-lft-identity79.9%
*-commutative79.9%
neg-mul-179.9%
sub-neg79.9%
flip-+97.7%
+-commutative97.7%
Applied egg-rr97.7%
*-commutative97.7%
associate-/r*97.7%
Simplified97.7%
div-inv97.7%
metadata-eval97.7%
times-frac99.8%
Applied egg-rr99.8%
Taylor expanded in a around 0 95.5%
Final simplification78.8%
(FPCore (a b) :precision binary64 (if (<= b 4e-12) (* (/ 0.5 (* a b)) (/ PI a)) (* PI (/ 0.5 (* b (* a b))))))
double code(double a, double b) {
double tmp;
if (b <= 4e-12) {
tmp = (0.5 / (a * b)) * (((double) M_PI) / a);
} else {
tmp = ((double) M_PI) * (0.5 / (b * (a * b)));
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 4e-12) {
tmp = (0.5 / (a * b)) * (Math.PI / a);
} else {
tmp = Math.PI * (0.5 / (b * (a * b)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 4e-12: tmp = (0.5 / (a * b)) * (math.pi / a) else: tmp = math.pi * (0.5 / (b * (a * b))) return tmp
function code(a, b) tmp = 0.0 if (b <= 4e-12) tmp = Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / a)); else tmp = Float64(pi * Float64(0.5 / Float64(b * Float64(a * b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 4e-12) tmp = (0.5 / (a * b)) * (pi / a); else tmp = pi * (0.5 / (b * (a * b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 4e-12], N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / a), $MachinePrecision]), $MachinePrecision], N[(Pi * N[(0.5 / N[(b * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4 \cdot 10^{-12}:\\
\;\;\;\;\frac{0.5}{a \cdot b} \cdot \frac{\pi}{a}\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \frac{0.5}{b \cdot \left(a \cdot b\right)}\\
\end{array}
\end{array}
if b < 3.99999999999999992e-12Initial program 76.8%
associate-*l*76.7%
*-rgt-identity76.7%
associate-/l*76.7%
metadata-eval76.7%
associate-*l/76.8%
*-lft-identity76.8%
sub-neg76.8%
distribute-neg-frac76.8%
metadata-eval76.8%
Simplified76.8%
metadata-eval76.8%
div-inv76.8%
*-commutative76.8%
clear-num76.8%
frac-times76.8%
*-un-lft-identity76.8%
frac-add76.7%
associate-/r/76.8%
*-un-lft-identity76.8%
*-commutative76.8%
neg-mul-176.8%
sub-neg76.8%
flip-+99.4%
+-commutative99.4%
Applied egg-rr99.4%
*-commutative99.4%
associate-/r*99.4%
Simplified99.4%
div-inv99.4%
metadata-eval99.4%
times-frac99.6%
Applied egg-rr99.6%
Taylor expanded in a around inf 73.0%
if 3.99999999999999992e-12 < b Initial program 79.9%
*-commutative79.9%
associate-*r*79.9%
associate-*r/79.9%
associate-*r*79.9%
*-rgt-identity79.9%
sub-neg79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
Simplified79.9%
*-commutative79.9%
associate-*r/79.9%
div-inv79.9%
metadata-eval79.9%
associate-*l*79.9%
*-commutative79.9%
Applied egg-rr97.6%
Taylor expanded in a around 0 93.4%
Final simplification78.3%
(FPCore (a b) :precision binary64 (if (<= b 1.1e-10) (* PI (/ 0.5 (* a (* a b)))) (* PI (/ 0.5 (* b (* a b))))))
double code(double a, double b) {
double tmp;
if (b <= 1.1e-10) {
tmp = ((double) M_PI) * (0.5 / (a * (a * b)));
} else {
tmp = ((double) M_PI) * (0.5 / (b * (a * b)));
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 1.1e-10) {
tmp = Math.PI * (0.5 / (a * (a * b)));
} else {
tmp = Math.PI * (0.5 / (b * (a * b)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.1e-10: tmp = math.pi * (0.5 / (a * (a * b))) else: tmp = math.pi * (0.5 / (b * (a * b))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.1e-10) tmp = Float64(pi * Float64(0.5 / Float64(a * Float64(a * b)))); else tmp = Float64(pi * Float64(0.5 / Float64(b * Float64(a * b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.1e-10) tmp = pi * (0.5 / (a * (a * b))); else tmp = pi * (0.5 / (b * (a * b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.1e-10], N[(Pi * N[(0.5 / N[(a * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Pi * N[(0.5 / N[(b * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.1 \cdot 10^{-10}:\\
\;\;\;\;\pi \cdot \frac{0.5}{a \cdot \left(a \cdot b\right)}\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \frac{0.5}{b \cdot \left(a \cdot b\right)}\\
\end{array}
\end{array}
if b < 1.09999999999999995e-10Initial program 76.8%
*-commutative76.8%
associate-*r*76.7%
associate-*r/76.7%
associate-*r*76.7%
*-rgt-identity76.7%
sub-neg76.7%
distribute-neg-frac76.7%
metadata-eval76.7%
Simplified76.7%
*-commutative76.7%
associate-*r/76.8%
div-inv76.8%
metadata-eval76.8%
associate-*l*76.8%
*-commutative76.8%
Applied egg-rr99.4%
Taylor expanded in a around inf 72.7%
if 1.09999999999999995e-10 < b Initial program 79.9%
*-commutative79.9%
associate-*r*79.9%
associate-*r/79.9%
associate-*r*79.9%
*-rgt-identity79.9%
sub-neg79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
Simplified79.9%
*-commutative79.9%
associate-*r/79.9%
div-inv79.9%
metadata-eval79.9%
associate-*l*79.9%
*-commutative79.9%
Applied egg-rr97.6%
Taylor expanded in a around 0 93.4%
Final simplification78.1%
(FPCore (a b) :precision binary64 (* PI (/ 0.5 (* (+ a b) (* a b)))))
double code(double a, double b) {
return ((double) M_PI) * (0.5 / ((a + b) * (a * b)));
}
public static double code(double a, double b) {
return Math.PI * (0.5 / ((a + b) * (a * b)));
}
def code(a, b): return math.pi * (0.5 / ((a + b) * (a * b)))
function code(a, b) return Float64(pi * Float64(0.5 / Float64(Float64(a + b) * Float64(a * b)))) end
function tmp = code(a, b) tmp = pi * (0.5 / ((a + b) * (a * b))); end
code[a_, b_] := N[(Pi * N[(0.5 / N[(N[(a + b), $MachinePrecision] * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \frac{0.5}{\left(a + b\right) \cdot \left(a \cdot b\right)}
\end{array}
Initial program 77.6%
*-commutative77.6%
associate-*r*77.5%
associate-*r/77.6%
associate-*r*77.6%
*-rgt-identity77.6%
sub-neg77.6%
distribute-neg-frac77.6%
metadata-eval77.6%
Simplified77.6%
*-commutative77.6%
associate-*r/77.6%
div-inv77.6%
metadata-eval77.6%
associate-*l*77.6%
*-commutative77.6%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (a b) :precision binary64 (* PI (/ 0.5 (* a (* a b)))))
double code(double a, double b) {
return ((double) M_PI) * (0.5 / (a * (a * b)));
}
public static double code(double a, double b) {
return Math.PI * (0.5 / (a * (a * b)));
}
def code(a, b): return math.pi * (0.5 / (a * (a * b)))
function code(a, b) return Float64(pi * Float64(0.5 / Float64(a * Float64(a * b)))) end
function tmp = code(a, b) tmp = pi * (0.5 / (a * (a * b))); end
code[a_, b_] := N[(Pi * N[(0.5 / N[(a * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \frac{0.5}{a \cdot \left(a \cdot b\right)}
\end{array}
Initial program 77.6%
*-commutative77.6%
associate-*r*77.5%
associate-*r/77.6%
associate-*r*77.6%
*-rgt-identity77.6%
sub-neg77.6%
distribute-neg-frac77.6%
metadata-eval77.6%
Simplified77.6%
*-commutative77.6%
associate-*r/77.6%
div-inv77.6%
metadata-eval77.6%
associate-*l*77.6%
*-commutative77.6%
Applied egg-rr98.9%
Taylor expanded in a around inf 64.0%
Final simplification64.0%
herbie shell --seed 2024131
(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))))